Re: [R] convert a character string to a name

2013-05-23 Thread Greg Snow
Here are a couple of approaches: > dftest<-data.frame(x=1:12, y=(1:12)%%4, z=(1:12)%%2) > x_test=c("x","y") > aggregate( dftest[,x_test], dftest['z'], FUN=mean ) z x y 1 0 7 1 2 1 6 2 > > ### Or > > tmp.f <- as.formula( paste( 'cbind(', + paste( x_test, collapse=',' ), + ') ~ z' ) ) > aggregat

Re: [R] convert a character string to a name

2013-05-23 Thread arun
y #1 0 7 1 #2 1 6 2 A.K. - Original Message - From: Blaser Nello To: arun ; jpm miao Cc: R help Sent: Thursday, May 23, 2013 3:29 AM Subject: RE: [R] convert a character string to a name If you want to use the character string: attach(dftest) aggregate(cbind(sapply(x_test, get))~z,

Re: [R] convert a character string to a name

2013-05-23 Thread jim holtman
try this: > dftest<-data.frame(x=1:12, y=(1:12)%%4, z=(1:12)%%2) > aggregate(cbind(x,y)~z, data=dftest, FUN=mean) z x y 1 0 7 1 2 1 6 2 > x_test=c("x","y") > a <- formula(paste0('cbind(' + , x_test[1] + , ',' + , x_test[2] +

Re: [R] convert a character string to a name

2013-05-23 Thread Blaser Nello
-help-boun...@r-project.org] On Behalf Of arun Sent: Donnerstag, 23. Mai 2013 09:19 To: jpm miao Cc: R help Subject: Re: [R] convert a character string to a name  with(dftest,aggregate(cbind(x,y),list(z),FUN=mean)) #  Group.1 x y #1   0 7 1 #2   1 6 2 #or library(plyr) ddply(dftest,.(z

Re: [R] convert a character string to a name

2013-05-23 Thread arun
 with(dftest,aggregate(cbind(x,y),list(z),FUN=mean)) #  Group.1 x y #1   0 7 1 #2   1 6 2 #or library(plyr) ddply(dftest,.(z),numcolwise(mean)) #  z x y #1 0 7 1 #2 1 6 2 A.K. - Original Message - From: jpm miao To: r-help Cc: Sent: Thursday, May 23, 2013 3:05 AM Subject: [R