Skip to content
Prev 345513 / 398502 Next

Working with data-frame

(I assume you you meant 'split', not 'spilt'.)

You did not show what you tried, but the following splits Dat by its "A1"
and "A2" columns (creating a list of data.frames):
   split(Dat, f=Dat[,c("A1","A2")])

aggregate(), in core R, combine the split and the lapply needed to
calculate groupwise sums.  E.g.,
  aggregate(Dat$C1, by=Dat[,c("A1","A2")], FUN=sum)
  aggregate(C1 ~ A1 + A2, data=Dat, FUN=sum)

The plyr and dplyr packages have other ways to do this sort of thing.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Nov 9, 2014 at 11:58 AM, Christofer Bogaso <
bogaso.christofer at gmail.com> wrote: