I am trying to get the cumulative sum of a variable (v) for groups (\"a\" and \"b\") within a dataframe. How can I get the result at the bottom -- whose rows are even number
split<- is a pretty weird beast
split<-
split(d$cs, d$g) <- lapply(split(d$v, d$g), cumsum)
leading to
> d g v cs 1 a 1 1 2 b 4 4 3 a 1 2 4 b 4 8 5 a 1 3 6 b 4 12 7 a 2 5 8 b 8 20 9 a 2 7 10 b 8 28 11 a 2 9 12 b 8 36