[R] by class...

arun smartpink111 at yahoo.com
Fri Dec 20 19:20:45 CET 2013


Hi,
You can also try:
library(reshape2)
dcast(as.data.frame(as.table(by(warpbreaks[,1],warpbreaks[,-1],sum))),wool~tension, value.var="Freq")


A.K.


On , arun <smartpink111 at yahoo.com> wrote:
Hi,
Try:
as.table(by(warpbreaks[,1],warpbreaks[,-1],sum))


#or to convert to data.frame

as.data.frame(as.table(by(warpbreaks[,1],warpbreaks[,-1],mean)))
A.K.





On Friday, December 20, 2013 12:39 PM, Onur Uncu <onuruncu at gmail.com> wrote:
I used the by() function on a data.frame to get sums of the data grouped by 2 factors. The function worked however the output is in a class called 'by'. Not familiar with this class. How can I turn the output into a nice table where columns represent values of factor1, row represent values of factor2 and the entries in the table are the sums that were calculated using the by function?

I did some web search which suggested using do.call(rbind, datframe_object) but this command gave the following error:
"Second argument must be a list"...


Thank you.
______________________________________________
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.



More information about the R-help mailing list