I need to reset the cumulative summation whenever there is zero in the vector using R. E.g. Input c(0,1,0,0,0,1,1,1,0,1,1) I want the output as 0,1,0,0,0,1,2,3,0,1,2. I checked multiple answers which answer resetting of sequence using functions, but those solutions did not work here.
Numeric sequence with condition, Create counter with multiple variables, Comp. Efficent way of resetting sequence if condition met ( R ) are some which I referred. I tried different combinations of cumsum, ave and getanID but can't seem to get the output I want.