Liviu Andronic
2011-Apr-07 16:39 UTC
[R] plyr workaround to converting by() to a data frame
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
rmailbox at justemail.net
2011-Apr-07 17:06 UTC
[R] plyr workaround to converting by() to a data frame
Is this what you are looking for? ddply ( .variables = c("grp1", "grp2", "grp3" ), .data = df, .fun = plyr::summarize, abmin = min(c(a, b, c) ), abmax = max ( c ( a, b, c) ) ) ----- Original message ----- From: "Liviu Andronic" <landronimirc at gmail.com> To: "r-help at r-project.org Help" <r-help at r-project.org> Date: Thu, 7 Apr 2011 18:39:30 +0200 Subject: [R] plyr workaround to converting by() to a data frame 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 ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.