[R] plyr workaround to converting by() to a data frame

Liviu Andronic landronimirc at gmail.com
Thu Apr 7 18:39:30 CEST 2011


Dear all
Is there a clean plyr version of the following by() and do.call(rbind,
...) construct:
> 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","grp3")], range)
> as.data.frame(dfsum)
Error in as.data.frame.default(dfsum) :
  cannot coerce class '"by"' into a data.frame
> do.call(rbind, dfsum)
     [,1] [,2]
[1,]    1   29
[2,]    2   30


Thank you
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail



More information about the R-help mailing list