I have this vector :
x = c(1,1,1,1,1,0,1,0,0,0,1,1)
And I want to do a cumulative sum for the positive numbers only. I should have the fol
Here's a possible solution using data.table v >= 1.9.5 and its new rleid funciton
rleid
library(data.table) as.data.table(x)[, cumsum(x), rleid(x)]$V1 ## [1] 1 2 3 4 5 0 1 0 0 0 1 2