Try ave instead of aggregate. If that does not do it, then look at the plyr package, probably the ddply function in that package.
-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Bond, Stephen > Sent: Tuesday, October 12, 2010 11:40 AM > To: r-help@r-project.org > Subject: [R] aggregate with cumsum > > Hello everybody, > > Data is > myd <- > data.frame(id1=rep(c("a","b","c"),each=3),id2=rep(1:3,3),val=rnorm(9)) > > I want to get a cumulative sum over each of id1. trying aggregate does > not work > > myd$pcum <- aggregate(myd[,c("val")],list(orig=myd$id1),cumsum) > > Please suggest a solution. In real the dataframe is huge so looping > with for and subsetting is not a great idea (still doable, though). > Thank you > > > Stephen B > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.