[R] Subtotals by id for a large number of columns XXXX
ruipbarradas at sapo.pt
Wed Oct 30 13:01:20 CET 2013
If I understand it correctly, just change mysum to the following.
Hope this helps,
Em 30-10-2013 11:07, Dan Abner escreveu:
> Hi everybody,
> I have data in the format of the example data below where essentially a
> large number of indicator variables (coded [0,1]) reflect traits of the
> same id across multiple rows. I need to represent the data in a 1 row per
> id format. I see this as being similar to converting from long to wide
> format, however, there is no time component here: The multiple rows here
> are all characteristics observed at the same measurement occasion. So,
> really I just need an individual sum for each variable (for a large number
> of variables) and for these to be all saved in the same row (along with the
> id variable and other demographics (e.g., "location").
> Here is the example df and the method I used first:
> mysum<-function(x) aggregate(x,by=list(d1$id),sum)
> Any help is appreciated!!
> [[alternative HTML version deleted]]
> 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