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

rmailbox at justemail.net rmailbox at justemail.net
Thu Apr 7 19:06:27 CEST 2011

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

Do you know how to read?
Do you know how to write?

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list