Re: [R] Convert the output of by() to a data frame

2011-02-08 Thread Matthew Dowle
There's a much shorter way. You don't need that ugly h() with all those $ and potential for bugs ! Using the original f : dt[,lapply(.SD,f),by=key(dt)] grp1 grp2 grp3 a b d xxx 1.00 81.00 161.00 xxx 10.00 90.00 17

Re: [R] Convert the output of by() to a data frame

2011-02-07 Thread Dennis Murphy
Hi: For this particular task, the aggregate() function and the doBy package provide nicely formatted output, but you may have to do some renaming. Let's try a more expansive toy example with which one can do a bit more. df <- data.frame(grp1 = rep(c('x', 'y'), each = 40), grp2

Re: [R] Convert the output of by() to a data frame

2011-02-07 Thread David Winsemius
On Feb 7, 2011, at 11:29 PM, Al Roark wrote: I'd like to summarize several variables in a data frame, for multiple groups, and store the results in a data.frame. To do so, I'm using by(). For example: df<- data .frame (a =1:10,b=11:20,c=21:30,grp1=c("x","y"),grp2=c("x","y"),grp3=c("x

[R] Convert the output of by() to a data frame

2011-02-07 Thread Al Roark
I'd like to summarize several variables in a data frame, for multiple groups, and store the results in a data.frame. To do so, I'm using by(). For example: df<-data.frame(a=1:10,b=11:20,c=21:30,grp1=c("x","y"),grp2=c("x","y"),grp3=c("x","y")) dfsum<-by(df[c("a","b","c")], df[c("grp1","grp2","grp