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
Try this one-liner...
Reduce(function(x,y) (x+y)*(y!=0), x, accumulate=T)