[R] Aggregate data frame across columns

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Nov 7 19:09:59 CET 2012


The best way to get an answer is to provide sample data and desired results (computed by hand or by any other available means). See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. 

In the vague question begets a vague answer department, I would use melt from the reshape package, and make some columns that contain unique key values for each time interval, and then use aggregate or ddply from the plyr package.
---------------------------------------------------------------------------
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.

Keith Weintraub <kw1958 at gmail.com> wrote:

>Folks,
>  I have a data frame with columns 200401, 200402, ..., 201207, 201208.
>
>These represent years/months. What would be the best way to sum these
>columns by year? What about by quarter?
>
>Thanks for your time,
>KW
>
>--
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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