Skip to content
Prev 237793 / 398500 Next

aggregate with cumsum

On Oct 12, 2010, at 1:40 PM, Bond, Stephen wrote:

            
Use ave instead of aggregate:

 > ave(myd$val, list(myd$id1), FUN=cumsum)
[1]  0.362123399 -1.538797831 -2.061733393 -2.038050242 -0.344382401  
-1.365281650
[7]  0.391181119 -0.258668053 -0.007736216

myd$pcum <- ave(myd$val, list(myd$id1), FUN=cumsum)