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.

Reply via email to