Re: [R] Dataframe with different lengths

2020-07-29 Thread Ulrik Stervbo via R-help
Hi Pedro, I see you use dplyr and ggplot2. Are you looking for something like this: ``` library(ggplot2) library(dplyr) test_data <- data.frame( year = c(rep("2018", 10), rep("2019", 8), rep("2020", 6)), value = sample(c(1:100), 24) ) test_data <- test_data %>% group_by(year) %>% mut

Re: [R] Dataframe by Serial ID

2020-01-08 Thread Eric Berger
Hi Thomas, Jeff is correct that this can be handled via merge, e.g. df3 <- merge( df2, df1, by="Serial", all=FALSE ) This operation is called an "inner join", and you could use other tools, such as the dplyr package to accomplish the same thing df3 <- dplyr::inner_join( df2, df1, by="Serial" ) H

Re: [R] Dataframe by Serial ID

2020-01-08 Thread David Winsemius
> On Jan 8, 2020, at 6:52 AM, Thomas Subia wrote: > > Colleagues, > > I have two data frames which look like this. > > Data frame 1 > > Serial Pre.HolePre.flowPre.Date > 1 30361 0.2419-Nov-19 > 2 30362

Re: [R] Dataframe by Serial ID

2020-01-08 Thread Jeff Newmiller
"merge" is generally the base R answer to this question, and there are equivalent functions in various contributed packages. However, it is necessary to identify which columns in each table uniquely identify each row ("primary key"). If your Serial 3036 shows up 10 times in the first table and

Re: [R] Dataframe columns are accessible by incomplete column names, is this a bug?

2019-07-18 Thread Patrick (Malone Quantitative)
But it's also a convenience feature. Note that $E returned null because there was an ambiguity. By the time you got to $Ex the column you were referencing was unambiguous and you didn't have to type out the whole thing. Useful if you have very long column names, for example imported from a spreadsh

Re: [R] Dataframe columns are accessible by incomplete column names, is this a bug?

2019-07-18 Thread Sarah Goslee
Hello Yannick, That behavior is documented in the help for subsetting ( ?'$' ): Both ‘[[’ and ‘$’ select a single element of the list. The main difference is that ‘$’ does not allow computed indices, whereas ‘[[’ does. ‘x$name’ is equivalent to ‘x[["name", exact = FALSE]]’.

Re: [R] Dataframe is character

2017-11-17 Thread Ivan Calandra
Good one, did not even notice that...! -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/pr

Re: [R] Dataframe is character

2017-11-17 Thread Petra Oleum
class("dat") is different from class(dat), which is what you actually want. On 17-11-17, P. Roberto Bakker wrote: > Hi everybody, > > Question: why are my dataframe and numeric variables a character? > > I read an excel file via readxl but my dataframe is a character, and > numeric variables, eg

Re: [R] Dataframe is character

2017-11-17 Thread Ivan Calandra
Hi Roberto, This often happens when there are some non-numeric characters. You would have to check it. Without more information, e.g. dput(dat), you will have to find by yourself. HTH, Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeologic

Re: [R] Dataframe Manipulation

2017-09-05 Thread Ulrik Stervbo
Hi Hemant, data_help <- data_help %>% # Add a dummy index for each purchase to keep a memory of the purchase since it will dissappear later on. You could also use row number mutate(Purchase_ID = 1:n()) %>% # For each purchase id group_by(Purchase_ID) %>% # Call the split_items function, which retu

Re: [R] Dataframe Manipulation

2017-09-04 Thread Hemant Sain
Hello Ulrik, Can you please explain this code means how and what this code is doing because I'm not able to understand it, if you can explain it i can use it in future by doing some Lil bit manipulation. Thanks data_help <- data_help %>% mutate(Purchase_ID = 1:n()) %>% group_by(Purchase_ID

Re: [R] Dataframe Manipulation

2017-08-31 Thread Ulrik Stervbo
Hi Hemant, the solution is really quite similar, and the logic is identical: library(readr) library(dplyr) library(stringr) library(tidyr) data_help <- read_csv("data_help.csv") cat_help <- read_csv("cat_help.csv") # Helper function to split the Items and create a data_frame split_items <- func

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
by using these two tables we have to create third table in this format where categories will be on the top and transaction will be in the rows, On 30 August 2017 at 16:42, Hemant Sain wrote: > Hello Ulrik, > Can you please once check this code again on the following data set > because it doesn't

Re: [R] Dataframe Manipulation

2017-08-30 Thread Ulrik Stervbo
Hi Hemant, Does this help you along? table_1 <- textConnection("Item_1;Item_2;Item_3 1KG banana;300ML milk;1kg sugar 2Large Corona_Beer;2pack Fries; 2 Lux_Soap;1kg sugar;") table_1 <- read.csv(table_1, sep = ";", na.strings = "", stringsAsFactors = FALSE, check.names = FALSE) table_2 <- textCon

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
Hey PIKAL, It's not a homework neithe that is the real dataset i have signer NDA for my company so that i can share the original data file, Actually I'm working on a market basket analysis task but not able to convert my existing data table to appropriate format so that i can apply Apriori algorith

Re: [R] Dataframe Manipulation

2017-08-30 Thread PIKAL Petr
Hi It seems to me like homework, there is no homework policy on this help list. What do you want to do with your table 3? It seems to me futile. Anyway, some combination of melt, merge, cast and regular expressions could be employed in such task, but it could be rather tricky. But be aware tha

Re: [R] dataframe columns class

2016-12-18 Thread Jeff Newmiller
The apply function operates on arrays, so your data frame is being converted to an array (matrix) before doing its thing. So use lapply or one of its variants. -- Sent from my phone. Please excuse my brevity. On December 18, 2016 9:07:52 AM PST, "Cleber N.Borges via R-help" wrote: >Why colu

Re: [R] dataframe columns class

2016-12-18 Thread Ista Zahn
Read ?apply and you shall be be enlightened. --Ista On Dec 18, 2016 12:09 PM, "Cleber N.Borges via R-help" wrote: > Why columns classes are function dependents? > Like this example: > > > for( i in 1:5 ) print( class( iris[,i] ) ) > [1] "numeric" > [1] "numeric" > [1] "numeric" > [1] "numeric"

Re: [R] dataframe rbind

2015-12-04 Thread Troels Ring
Thanks a lot - I should have seen that Best wishes Troels Den 04-12-2015 kl. 17:09 skrev PIKAL Petr: Hi Maybe little bit of studying how functions work can be useful rbind uses to bind two objects together, however you give it only one. Use DF <- rbind(DF, data.frame(a=rnorm(10),b=runif(10),

Re: [R] dataframe rbind

2015-12-04 Thread peter dalgaard
On 04 Dec 2015, at 17:03 , Troels Ring wrote: > Dear friends - I have a very simple question - > I generate a number of dataframes with identical names and want to combine > them into one large dataframe with the same names - > here is an example > > DF <- data.frame(a=rnorm(10),b=runif(10),ID

Re: [R] dataframe rbind

2015-12-04 Thread Bert Gunter
Try reading and following the Help file, ?rbind.data.frame. You are inventing your own syntax, not using R's. Incidentally, growing the frames as you do is generally a bad idea. Search r-help archives for why. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And

Re: [R] dataframe rbind

2015-12-04 Thread David L Carlson
This will work, although depending on what you are trying to do, there may be a better way: > DF <- data.frame(a=rnorm(10),b=runif(10),ID=0) > for (i in 1:10){ + DF <- rbind(DF, data.frame(a=rnorm(10),b=runif(10),ID=i))} > str(DF) 'data.frame': 110 obs. of 3 variables: $ a : num 0.792 0.141

Re: [R] dataframe rbind

2015-12-04 Thread PIKAL Petr
Hi Maybe little bit of studying how functions work can be useful rbind uses to bind two objects together, however you give it only one. Use DF <- rbind(DF, data.frame(a=rnorm(10),b=runif(10),ID=i)) instead. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-pro

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-30 Thread PIKAL Petr
Hi Please do not use html formating in your post. It does not bring any advantage. See inline. From: Verena Weinbir [mailto:vwein...@gmail.com] Sent: Thursday, May 29, 2014 3:33 PM To: PIKAL Petr Subject: Re: [R] Dataframe: Average cells of two rows and replace them with one row Hey, Thank you

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-29 Thread PIKAL Petr
-help Subject: Re: [R] Dataframe: Average cells of two rows and replace them with one row Hello, thank you for your reply. Actually, the whole rows would have to be averaged anyways - my mistake :-) Besides the first column "name" there is one other string (chr) variable "Test&q

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-29 Thread Verena Weinbir
nal Message- > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > > project.org] On Behalf Of Verena Weinbir > > Sent: Wednesday, May 28, 2014 2:00 PM > > To: arun > > Cc: r-help > > Subject: Re: [R] Dataframe: Average cells of two rows and repl

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-28 Thread PIKAL Petr
41. Show us at least structure of your data frame. ?str Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Verena Weinbir > Sent: Wednesday, May 28, 2014 2:00 PM > To: arun > Cc: r-help > Su

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-28 Thread Verena Weinbir
Hey guys, thank you very much for your help. Since I am a R-newbie I am still checking out how your code works and how I could adapt it to my dataframe, which has 124 rows and 41 columns/variables. The first column would be "name", the last ones, 40 and 41, contain the cells I want to average fo

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread arun
Hi, You can also try: dat <- read.table(text="Name C1 C2 C3   1  A  3  3  5   2  B  2  7  4   3  C  4  3  3   4  C  4  4  6   5  D  5  5  3",sep="",header=TRUE,stringsAsFactors=FALSE)  library(plyr)  ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE)) A.K. On Tuesday, May 27, 2014 4:08 PM, Verena We

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread Rui Barradas
Hello, Try the following. dat <- read.table(text = " Name C1 C2 C3 1 A 3 3 5 2 B 2 7 4 3 C 4 3 3 4 C 4 4 6 5 D 5 5 3 ", header = TRUE) str(dat) aggregate(dat[, -1], list(dat$Name), mean) Hope this helps, Rui Barradas Em 27-05-2014 21:06, Verena Weinbir escreve

Re: [R] Dataframe: Average cells of two rows and replace them with one row

2014-05-27 Thread Greg Snow
Look at the aggregate function. As long as you have a column like Name that indicates which rows should be averaged together it will work (technically it will average the other rows as well, but since the average of 1 number is that number you will not see a difference). On Tue, May 27, 2014 at 2

Re: [R] dataframe

2014-04-29 Thread arun
Hi, It is better to show example data using ?dput(). dat <- structure(list(row.names = 1:4, XYZ = c("sample", "sample2", "sample3", "sample4"), `000_001` = c("sample", "Au5", "C", "C" ), `000_002` = c("sample", "Au32", "C", "Au4"), `000_003` = c("sample", "Au5", "A", "AC")), .Names = c("row.nam

Re: [R] dataframe calculations based on certain values of a column

2014-03-27 Thread johannesradin...@gmail.com
Thanks, your solution using ave() works perfectly. /johannes -Ursprüngliche Nachricht- Von: Bert Gunter An: Johannes Radinger Cc: R help Gesendet: Mittwoch, 26. März 2014 16:45:43 GMT+00:00 Betreff: Re: [R] dataframe calculations based on certain values of a column I believe this

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Noah Marconi
dplyr's group_by and mutate can create those columns for you: var1 <- c("a","b","c","a","b","c","a","b","c") var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z") var3 <- c(1,2,2,5,2,6,7,4,4) df <- data.frame(var1,var2,var3) dt <- tbl_df(df) dt %.% group_by(var2) %.% mutate( div = var3[var1 =

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Berend Hasselman
On 26-03-2014, at 17:09, Johannes Radinger wrote: > Hi, > > I have data in a dataframe in following structure > var1 <- c("a","b","c","a","b","c","a","b","c") > var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z") > var3 <- c(1,2,2,5,2,6,7,4,4) > df <- data.frame(var1,var2,var3) > > Now I'd like to

Re: [R] dataframe calculations based on certain values of a column

2014-03-26 Thread Bert Gunter
I believe this will generalize. But check carefully! Using your example (Excellent!), use ave(): with(df,ave(seq_along(var1),var2,FUN=function(i) var3[i]/var3[i][var1[i]=="c"])) [1] 0.500 1.000 1.000 0.833 0.333 1.000 1.750 [8] 1.000 1.000 This is kind of a l

Re: [R] dataframe manipulation

2013-12-13 Thread arun
Hi, Try:  d[match(unique(d$fac),d$fac),] A.K. On Friday, December 13, 2013 4:17 PM, Gang Chen wrote: Suppose I have a dataframe defined as     L3 <- LETTERS[1:3]     (d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)))   x  y fac 1  1  1  C 2  1  2  A 3  1  3 

Re: [R] dataframe manipulation

2013-12-13 Thread William Dunlap
-project.org] On > Behalf > Of Gang Chen > Sent: Friday, December 13, 2013 1:35 PM > To: arun > Cc: R help > Subject: Re: [R] dataframe manipulation > > Perfect! Thanks a lot, A.K! > > > On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > > >

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Another neat solution! Thanks a lot, Sarah! On Fri, Dec 13, 2013 at 4:35 PM, Sarah Goslee wrote: > What about: > > lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) > > > Thanks for the reproducible example. If you put set.seed(123) before > the call to sample, then everyone who tries it

Re: [R] dataframe manipulation

2013-12-13 Thread Sarah Goslee
What about: lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) Thanks for the reproducible example. If you put set.seed(123) before the call to sample, then everyone who tries it will get the same data frame d. Sarah On Fri, Dec 13, 2013 at 4:15 PM, Gang Chen wrote: > Suppose I have a

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Perfect! Thanks a lot, A.K! On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > Hi, > Try: > d[match(unique(d$fac),d$fac),] > A.K. > > > On Friday, December 13, 2013 4:17 PM, Gang Chen > wrote: > Suppose I have a dataframe defined as > > L3 <- LETTERS[1:3] > (d <- data.frame(cbind(x

Re: [R] Dataframe and conditions

2013-05-14 Thread arun
#this should also work  within(X,a<- ifelse(b,c,a)) #  a b c #1 2  TRUE 2 #2 2  TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE 2 #6 2  TRUE 2 A.K. - Original Message - From: Pascal Oettli To: fgrelier Cc: r-help@r-project.org Sent: Tuesday, May 14, 2013 4:47 AM Subject: Re:

Re: [R] Dataframe and conditions

2013-05-14 Thread Frédéric Grelier
ine- De : arun [mailto:smartpink...@yahoo.com] Envoyé : mardi 14 mai 2013 15:19 À : Pascal Oettli Cc : R help; fgrelier Objet : Re: [R] Dataframe and conditions #this should also work  within(X,a<- ifelse(b,c,a)) #  a b c #1 2  TRUE 2 #2 2  TRUE 2 #3 1 FALSE 2 #4 1 FALSE 2 #5 1 FALSE

Re: [R] Dataframe and conditions

2013-05-14 Thread Pascal Oettli
Hello, One approach is using "ifelse": > X <- data.frame(a=c(1,1,1,1,1,1), b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2)) > X a b c 1 1 TRUE 2 2 1 TRUE 2 3 1 FALSE 2 4 1 FALSE 2 5 1 FALSE 2 6 1 TRUE 2 > > X <- within(X, a <- ifelse(b==TRUE, c, a)) > X a b c 1 2 TRUE 2

Re: [R] Dataframe and conditions

2013-05-14 Thread Rui Barradas
Hello, Try the following. X$a[X$b] <- X$c[X$b] Hope this helps, Rui Barradas Em 14-05-2013 09:06, fgrelier escreveu: I have in a dataframe X : 3 Variables X$a , X$b, X$c I would like to replace in X the values of X$a by the values of X$c but only when X$b=="TRUE" I have tried to put in

Re: [R] Dataframe manipulation

2013-03-30 Thread englishfellow
Fantastic, thanks alot for that! Take care. Adam. Date: Sat, 30 Mar 2013 01:14:49 -0700 From: ml-node+s789695n466289...@n4.nabble.com To: english.fel...@hotmail.com Subject: Re: Dataframe manipulation Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",s

Re: [R] Dataframe manipulation

2013-03-30 Thread arun
Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE)  str(dat1) #'data.frame':    102 obs. of  5 variables: # $ species  : chr  "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe" ... # $ period   : chr  "dusk" "dusk" "dusk" "dusk" ... # $

Re: [R] Dataframe,Matrix,Table

2012-11-08 Thread John Kane
I don't understand what you mean by a header line but does this do the other two for you? mydata <- data.frame( 1:5, 21: 25) mydata names(mydata) <- c("alph", "louie") rownames (mydata) <- letters[1:5] mydata John Kane Kingston ON Canada > -Original Message- > From: kokila.krish.

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Ajay Askoolum
Thank you Jorge & Michael. I was being stupid - its the only explanation! The line I had been executing was mtcars[rownames=="Valiant"] # missing rownames argument but the line I quoted in my post was mtcars[rownames(mtcars) != "Valiant",]  # How could I write the correct line in the mailin

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread R. Michael Weylandt
Hi Ajay, Like Jorge, I can't seem to reproduce the behavior you are worried about. mtcars[rownames(mtcars) != "Valiant",] returns a 31x11 data.frame as expected. When you say it "fails," what error message / result are you seeing? Michael On Fri, Feb 17, 2012 at 3:27 AM, Jorge I Velez wrote

Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Jorge I Velez
Hi Ajay, In the first case, you need "==" instead of "=" : R> mtcars[ rownames(mtcars) == "Valiant", ] mpg cyl disp hp drat wt qsec vs am gear carb Valiant 18.1 6 225 105 2.76 3.46 20.22 1 031 For the second case, R> mtcars[rownames(mtcars) != "Valiant",] will do it. See als

Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
This works but I do not know if there is a better way tmp = df[df$myvalue<2000,] ind = match(tmp$myvalue, df$myvalue) res = df$DateTime[ind] solution = list(ind[1], res[1]) -- View this message in context: http://r.789695.n4.nabble.com/dataframe-how-to-select-an-element-from-a-row-tp4311881p43

Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
Thank you Jorge and Florent for your responses. Now, I 'd like to get the date *(and its index) *where myvalue < 2000 for the first time. I expect for a result like (index, date) = (3, 2012-01-07 ) This way does not work: ind = match(df$myvalue <2000, df$myvalue) res = df$DateTime[ind] -- View

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Thank you Florent, it really helps. Regards, Jorge.- On Thu, Jan 19, 2012 at 7:28 PM, Florent D. <> wrote: > Another possibility: > > df$Date[match(1800, df$myvalue)] > > match() stops at the first value encountered so it may be a bit faster > than a full subset(), depending on your table size.

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Florent D.
Another possibility: df$Date[match(1800, df$myvalue)] match() stops at the first value encountered so it may be a bit faster than a full subset(), depending on your table size. Another difference: this approach would return NA if there was no match, subset(...)[1, ] would trigger an error. Depend

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Hi ikuzar, Try subset(df, myvalue == 1800, select = Date)[1, ] See ?subset for more information. HTH, Jorge.- On Thu, Jan 19, 2012 at 6:42 PM, ikuzar <> wrote: > Hi, > I 'd like to select the Date where myvalue =1800 appears the* first time*. > > For instance: > df =data.frame(date, myvalue,

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Johannes Radinger
t; Datum: Thu, 24 Nov 2011 09:12:57 -0500 > Von: Gabor Grothendieck > An: Johannes Radinger > CC: r-help@r-project.org > Betreff: Re: [R] dataframe indexing by number of cases per group > On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger > wrote: > > Hello, > > &g

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Gabor Grothendieck
On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger wrote: > Hello, > > assume we have following dataframe: > > group <-c(rep("A",5),rep("B",6),rep("C",4)) > x <- c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) > df <- data.frame(group,x) > > Now I want to select all cases (rows) for those groups > whi

Re: [R] dataframe indexing by number of cases per group

2011-11-24 Thread Dennis Murphy
A very similar question was asked a couple of days ago - see the thread titled "Removing rows in dataframe w'o duplicated values" - in particular, the responses by Dimitris Rizopoulos and David Winsemius. The adaptation to this problem is df[ave(as.numeric(df$group), as.numeric(df$group), FUN = le

Re: [R] dataframe - column value calculation in R

2011-05-26 Thread Timothy Bates
On 26 May 2011, at 08:02, Vijayan Padmanabhan wrote: > I have a requirement for which I am seeking help. Best to just ask, compactly. This is a very straightforward question: best to read on how to use R: You are just set 1 column of a dataframe to a value based on the others, applying this to

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
sDaply2(X, X$ID) # list is not a timeSeries object str(cbind(t(res))) res <- as.timeSeries(cbind(t(res))) -Original Message- From: h.wick...@gmail.com [mailto:h.wick...@gmail.com] On Behalf Of Hadley Wickham Sent: 14 March 2011 15:07 To: Daniele Amberti Cc: r-help@r-project.org Subjec

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Hadley Wickham
>  res <- daply(X, "ID", buildTimeSeriesFromDataFrame2, .parallel = FALSE) >  return(res) > } > # tsDaply2 .parallel = FALSE work but list discart timeSeries class > > # bind after ts creation > res <- tsDaply2(X, X$ID) > # list is not a timeSeries object &g

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
ot;, buildTimeSeriesFromDataFrame2, .parallel = FALSE) return(res) } # tsDaply2 .parallel = FALSE work but list discart timeSeries class # bind after ts creation res <- tsDaply2(X, X$ID) # list is not a timeSeries object str(cbind(t(res))) res <- as.timeSeries(cbind(t(res))) stopW

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Hadley Wickham
Well, I'd start by removing all explicit use of environments, which makes you code very hard to follow. Hadley On Monday, March 14, 2011, Daniele Amberti wrote: > I found that plyr:::daply is more efficient than base:::by (am I doing > something wrong?), below updated code for comparison (I als

Re: [R] dataframe to a timeseries object

2011-03-14 Thread Daniele Amberti
I found that plyr:::daply is more efficient than base:::by (am I doing something wrong?), below updated code for comparison (I also fixed a couple things). Function daply from plyr package has also a .parallel argument and I wonder if creating timeseries objects in parallel and then combining th

Re: [R] dataframe: string operations on columns

2011-01-19 Thread Ivan Calandra
Well, my solution with the loop might be slower (even though I don't see any difference with my system, at least with up to 100 lines and 3 strings to separate), but it works whatever the number of strings. But I should have renamed the columns outside of the loop: names(df)[2:3] <- paste("a", 1

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Waclaw Kusnierczyk
On 01/18/2011 07:05 PM, Henrique Dallazuanna wrote: > Or: > > read.table(textConnection(as.matrix(df)), sep = " ") no, that's too simple: you can't use regular expressions. (well, i guess it's enough for the original problem.) vQ > > > On Tue, Jan 18, 2011 at 11:02 PM, Waclaw Kusnierczyk

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Henrique Dallazuanna
Or: read.table(textConnection(as.matrix(df)), sep = " ") On Tue, Jan 18, 2011 at 11:02 PM, Waclaw Kusnierczyk wrote: > Assuming every row is split into exactly two values by whatever string you > choose as split, one fancy exercise in R data structures is > >dfsplit = function(df, split) >

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Waclaw Kusnierczyk
Assuming every row is split into exactly two values by whatever string you choose as split, one fancy exercise in R data structures is dfsplit = function(df, split) as.data.frame( t( structure(dim=c(2, nrow(df)), unlist(

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Niels Richard Hansen
On 2011-01-18 08:14, Ivan Calandra wrote: Hi, I guess it's not the nicest way to do it, but it should work for you: #create some sample data df<- data.frame(a=c("A B", "C D", "A C", "A D", "B D"), stringsAsFactors=FALSE) #split the column by space df_split<- strsplit(df$a, split=" ") #place th

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Peter Ehlers
On 2011-01-18 08:14, Ivan Calandra wrote: Hi, I guess it's not the nicest way to do it, but it should work for you: #create some sample data df<- data.frame(a=c("A B", "C D", "A C", "A D", "B D"), stringsAsFactors=FALSE) #split the column by space df_split<- strsplit(df$a, split=" ") #place th

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Hadley Wickham
> how can I perform a string operation like strsplit(x," ")  on a column of a > dataframe, and put the first or the second item of the split into a new > dataframe column? > (so that on each row it is consistent) Have a look at str_split_fixed in the stringr package. Hadley -- Assistant Profes

Re: [R] dataframe: string operations on columns

2011-01-18 Thread Ivan Calandra
Hi, I guess it's not the nicest way to do it, but it should work for you: #create some sample data df <- data.frame(a=c("A B", "C D", "A C", "A D", "B D"), stringsAsFactors=FALSE) #split the column by space df_split <- strsplit(df$a, split=" ") #place the first element into column a1 and the

Re: [R] dataframe, simulating data

2011-01-02 Thread Sarah
Thanks, Petr! With your script my problem is solved. David, thanks for your help and time as well!! I really appreciate it. -- View this message in context: http://r.789695.n4.nabble.com/dataframe-simulating-data-tp3169246p3170764.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] dataframe, simulating data

2010-12-31 Thread Petr Savicky
On Fri, Dec 31, 2010 at 05:05:08AM -0800, Sarah wrote: > > I'm sorry, I don't think I've made myself clear enough. > > Cases have been randomly assigned to one of the two groups, with certain > probabilities (based on other variables). > So, if there are too many people (i.e., more than 34) assig

Re: [R] dataframe, simulating data

2010-12-31 Thread David Winsemius
On Dec 31, 2010, at 8:32 AM, David Winsemius wrote: On Dec 31, 2010, at 8:05 AM, Sarah wrote: I'm sorry, I don't think I've made myself clear enough. Cases have been randomly assigned to one of the two groups, with certain probabilities (based on other variables). So, if there are too m

Re: [R] dataframe, simulating data

2010-12-31 Thread David Winsemius
On Dec 31, 2010, at 8:05 AM, Sarah wrote: I'm sorry, I don't think I've made myself clear enough. Cases have been randomly assigned to one of the two groups, with certain probabilities (based on other variables). So, if there are too many people (i.e., more than 34) assigned to group 0,

Re: [R] dataframe, simulating data

2010-12-31 Thread Sarah
I'm sorry, I don't think I've made myself clear enough. Cases have been randomly assigned to one of the two groups, with certain probabilities (based on other variables). So, if there are too many people (i.e., more than 34) assigned to group 0, I would like to sample 34 cases from group 0, and g

Re: [R] dataframe, simulating data

2010-12-31 Thread Petr Savicky
On Fri, Dec 31, 2010 at 01:51:18AM -0800, Sarah wrote: > > Dear all, > > I'm having trouble with my dataframe, and I hope someone can help me out... > I have data from 40 subjects, displayed in a dataframe. I have randomly > assigned subjects to group 1 or 0 (mar.y==0 or mar.y==1, with probabilit

Re: [R] dataframe, simulating data

2010-12-31 Thread Jim Lemon
On 12/31/2010 08:51 PM, Sarah wrote: Dear all, I'm having trouble with my dataframe, and I hope someone can help me out... I have data from 40 subjects, displayed in a dataframe. I have randomly assigned subjects to group 1 or 0 (mar.y==0 or mar.y==1, with probabilities used). In the end, I wan

Re: [R] Dataframe from list of similar lists: not _a_ way, but _the best_ way

2010-12-07 Thread Brian Diggs
On 12/7/2010 1:03 AM, Nick Sabbe wrote: Hi All. I often find myself in this situation: . Based on some vector (or list) of values, I need to calculate a few new values for each of them, where some of the new values are numbers, but some are more of descriptive nature (so: character stri

Re: [R] dataframe, transform, strsplit

2010-10-25 Thread Gabor Grothendieck
On Mon, Oct 25, 2010 at 1:20 PM, Matthew Pettis wrote: > Thanks Gabor and Jim, > Both solutions worked equally well for me (now I have an embarrassment of > riches for a solution :-) ). > Now that my main problem is solved, I am happy, but I was wondering if > anyone would care to comment as to wh

Re: [R] dataframe, transform, strsplit

2010-10-25 Thread Matthew Pettis
Thanks Gabor and Jim, Both solutions worked equally well for me (now I have an embarrassment of riches for a solution :-) ). Now that my main problem is solved, I am happy, but I was wondering if anyone would care to comment as to why my 'strsplit' solution doesn't behave the way I think it shoul

Re: [R] dataframe, transform, strsplit

2010-10-25 Thread Gabor Grothendieck
On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis wrote: > Hi, > > I have a dataframe that has a column of vectors that I need to extract off > the character string before the first '.' character and put it into a > separate column.  I thought I could use 'strsplit' for it within > 'transform', but

Re: [R] dataframe, transform, strsplit

2010-10-25 Thread jim holtman
try this: > df have want 1 a.b.ca 2 d.e.fd 3 g.h.ig > df$get <- gsub("^([^.]+).*", "\\1", df$have) > df have want get 1 a.b.ca a 2 d.e.fd d 3 g.h.ig g On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis wrote: > Hi, > > I have a dataframe that has a column of ve

Re: [R] dataframe of dataframes?

2010-09-14 Thread raje...@cse.iitm.ac.in
This is great. Thanks - Original Message - From: Henrik Bengtsson To: Jeff Newmiller Cc: raje...@cse.iitm.ac.in, r-help Sent: Tue, 14 Sep 2010 12:27:38 +0530 (IST) Subject: Re: [R] dataframe of dataframes? You can create an empty matrix (or even array) of list elements and then assign

Re: [R] dataframe of dataframes?

2010-09-13 Thread Henrik Bengtsson
You can create an empty matrix (or even array) of list elements and then assign your data frames to whichever element you want. Example: # Allocate empty matrix... > x <- matrix(list(), nrow=2, ncol=3); # ...alternatively > x <- array(list(), dim=c(2,3)); > print(x); [,1] [,2] [,3] [1,] NULL

Re: [R] dataframe of dataframes?

2010-09-13 Thread Jeff Newmiller
raje...@cse.iitm.ac.in wrote: Hi, I create several dataframes in a nested loop and would like to maintain them in a matrix form with each dataframe represented by the row and the column. How can I do this? You can't, at least as you describe it. However, you can add a column for "row ID"

Re: [R] dataframe selection using a multi-value key

2010-09-07 Thread Markus Weisner
Hi Erik and Jim. Both solutions did the trick. Thanks you!! --Markus On Tue, Sep 7, 2010 at 9:05 PM, jim holtman wrote: > try this: > > > merged_data = merge(incidents, responses, by=c("INC_NO", "INC_YEAR"), > all=TRUE) > > # responses that don't match > > subset(merged_data, is.na(INC_TYPE),

Re: [R] dataframe selection using a multi-value key

2010-09-07 Thread jim holtman
try this: > merged_data = merge(incidents, responses, by=c("INC_NO", "INC_YEAR"), > all=TRUE) > # responses that don't match > subset(merged_data, is.na(INC_TYPE), select=c(INC_NO, INC_YEAR, UNIT_TYPE)) INC_NO INC_YEAR UNIT_TYPE 11 8 2018E3 12 8 2018E7 13

Re: [R] dataframe selection using a multi-value key

2010-09-07 Thread Erik Iverson
Hello, On 09/07/2010 07:25 PM, Markus Weisner wrote: I am merging two dataframes using a relational key (incident number and incident year), but not all the records match up. I want to be able to review only the records that cannot be merged for each individual dataframe (essentially trying to

Re: [R] dataframe row names from list

2010-09-06 Thread Jim Lemon
On 09/06/2010 09:41 PM, raje...@cse.iitm.ac.in wrote: Hi, I have a list which looks like this... str(y) List of 10 $ : chr [1:4] "ABCD" "5" "0" "1" $ : chr [1:4] "DEF" "15" "1" "16" $ : chr [1:4] "AAA" "2" "17" "8" $ : chr [1:4] "SSS" "15" "25" "1" $ : chr [1:4] "III" "15" "26" "4"

Re: [R] dataframe row names from list

2010-09-06 Thread Ivan Calandra
Hi! I'm sure there's an easier way, but that works for me: test_list <- list(c("ABC","5","0"), c("DEF","10","1")) ##just a part of your example, think about using dput() to create a copy/pastable example test_df <- t(as.data.frame(test_list)[-1,]) rownames(test_df) <- t(as.data.frame(test_list

Re: [R] Dataframe to word, using R2wd

2010-05-15 Thread Tal Galili
Fishery Biologist > Department of the Interior > US Fish & Wildlife Service > California, USA > > > > - Original Message > > From: Tal Galili > > To: Jeremy Miles > > Cc: r-help@r-project.org > > Sent: Sat, May 15, 2010 1:03:12 AM > >

Re: [R] Dataframe to word, using R2wd

2010-05-15 Thread Felipe Carrillo
Wildlife Service California, USA - Original Message > From: Tal Galili > To: Jeremy Miles > Cc: r-help@r-project.org > Sent: Sat, May 15, 2010 1:03:12 AM > Subject: Re: [R] Dataframe to word, using R2wd > > Hi Jeremy, 1) This is not the command to use on data.frames,

Re: [R] Dataframe to word, using R2wd

2010-05-15 Thread Tal Galili
Hi Jeremy, 1) This is not the command to use on data.frames, it is: wdTable 2) There is a slightly newer version of R2wd, that (for now) can only be downloaded here: http://www.r-statistics.com/2010/05/exporting-r-output-to-ms-word-with-r2wd-an-example-session/ (That posts also offers a step by st

Re: [R] Dataframe horizontal scrolling

2010-05-10 Thread Emmanuel Charpentier
under Unix/X11 (and IIRC under Windows), edit(some.data.frame) will invoke a smallish spreadsheet-like data editor, which will allow you to move around your data with no fuss. I probably wouldn't use it for any serious data entry, but found damn useful in a lot of data-debugging situations (you kno

Re: [R] Dataframe horizontal scrolling

2010-05-10 Thread Erik Iverson
Perhaps even ?View would be useful here. I've never used R Commander, so don't know it would be useful in that environment. Michael H wrote: R experts, I am working with large multivariable data frames (> 50 variables) and I would like to scroll horizontally across my output to view each d

Re: [R] Dataframe horizontal scrolling

2010-05-10 Thread Ista Zahn
Hi Mike, You can set options(width = x), where x equals the number of columns. -Ista On Monday 10 May 2010 16:06:54 Michael H wrote: > R experts, > > I am working with large multivariable data frames (> 50 variables) > and I would like to scroll horizontally across my output > to view each data

Re: [R] dataframe

2010-04-21 Thread jim holtman
Here is one way of doing it: > x <- read.table(textConnection("CFISCAFIRMS YEAR VARVALUE + 20345 nike2005EC01 34 + 20345 nike2006 EC01 45 + 56779

  1   2   >