[R] by class...

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Dec 20 20:58:41 CET 2013


You seem to be falling prey to a common misconception that "R" is some monolithic tool, when in fact it is a herd of cats.

The "by" function, from the "base" package, returns a list of results returned by your function. One approach to making a data frame out of that is to use the simplify2array function, transpose, and convert to data frame.

However, there are many other ways to aggregate data as well. Packages plyr, sqldf, data.table all have strengths and weaknesses, but you must always keep in mind that they are contributed packages and you have to refer to the package name if you ask here about using functions from them.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

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