Re: [R] different interface to by (tapply)?

2010-08-30 Thread ivo welch
mercy!!! ;-) thanks, everyone. sure beats me trying to reinvent a slower version of the wheel. came in very handy. I think it would be nice to see some of these pointers in the "?by" manual page. not sure who to ask to do this, but maybe this person reads r-help. /iaw Ivo Welch (ivo.we

Re: [R] different interface to by (tapply)?

2010-08-30 Thread Gabor Grothendieck
On Mon, Aug 30, 2010 at 3:54 PM, Dennis Murphy wrote: > Hi: > > You've already gotten some good replies re aggregate() and plyr; here are > two more choices, from packages doBy and data.table, plus the others for > a contained summary: > >  key <- c(1,1,1,2,2,2) >  val1 <- rnorm(6) >  indf <- data

Re: [R] different interface to by (tapply)?

2010-08-30 Thread Dennis Murphy
Hi: You've already gotten some good replies re aggregate() and plyr; here are two more choices, from packages doBy and data.table, plus the others for a contained summary: key <- c(1,1,1,2,2,2) val1 <- rnorm(6) indf <- data.frame( key, val1) outdf <- by(indf, indf$key, function(x) c(m=mean(x)

Re: [R] different interface to by (tapply)?

2010-08-30 Thread David Winsemius
On Aug 30, 2010, at 9:19 AM, ivo welch wrote: dear R experts: has someone written a function that returns the results of by() as a data frame? of course, this can work only if the output of the function that is an argument to by() is a numerical vector. presumably, what is now names(byobject

Re: [R] different interface to by (tapply)?

2010-08-30 Thread William Dunlap
m 1.71 1.41 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of ivo welch > Sent: Monday, August 30, 2010 6:19 AM > To: r-help > Subject: [R] different i

Re: [R] different interface to by (tapply)?

2010-08-30 Thread Erik Iverson
I can definitely recommend the "plyr" package for these sorts of operations. http://had.co.nz/plyr/ ivo welch wrote: dear R experts: has someone written a function that returns the results of by() as a data frame? of course, this can work only if the output of the function that is an argumen

Re: [R] different interface to by (tapply)?

2010-08-30 Thread ivo welch
perfect. this is the R way to do it quick and easy. thank you, marc. (PS, in my earlier example, what I wanted was aggregate( . ~ key, data=indf, FUN = function(x) c(m=mean(x), s=sd(x))) ) Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com) On Mon, Aug 30, 2010 at 10:47 AM, Marc Sch

Re: [R] different interface to by (tapply)?

2010-08-30 Thread Marc Schwartz
FYI, since R version 2.11.0, aggregate() can return a vector of summary results, rather than just a scalar: > aggregate(iris$Sepal.Length, list(Species = iris$Species), function(x) c(Mean = mean(x), SD = sd(x))) Speciesx.Mean x.SD 1 setosa 5.006 0.3524897 2 ver

Re: [R] different interface to by (tapply)?

2010-08-30 Thread ivo welch
serious? key <- c(1,1,1,2,2,2) val1 <- rnorm(6) indf <- data.frame( key, val1) outdf <- by(indf, indf$key, function(x) c(m=mean(x), s=sd(x)) ) outdf indf$key: 1 m.key m.val1 s.key s.val1 1. 0.6005 0. 1.0191

Re: [R] different interface to by (tapply)?

2010-08-30 Thread Henrique Dallazuanna
Try this: as.data.frame(by( indf, indf$charid, function(x) c(m=mean(x), s=sd(x)) )) On Mon, Aug 30, 2010 at 10:19 AM, ivo welch wrote: > dear R experts: > > has someone written a function that returns the results of by() as a > data frame? of course, this can work only if the output of the >

[R] different interface to by (tapply)?

2010-08-30 Thread ivo welch
dear R experts: has someone written a function that returns the results of by() as a data frame?   of course, this can work only if the output of the function that is an argument to by() is a numerical vector. presumably, what is now names(byobject) would become a column in the data frame, and the