Displaying 2 results from an estimated 2 matches for "dfsum".
Did you mean:
dfsub
2011 Apr 07
1
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,...
2011 Feb 08
2
Convert the output of by() to a data frame
...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","grp3")], range)
The result has a class of "by" and a mode of "list". I'm new to R and can't find any documentation on this class, and don't see methods for it...