powered by
Cumulative sum unless reset
cumsum_reset(x, y = as.integer(x))
A logical vector indicating when the sum should continue.
Optional: a numeric vector the same length as x to cumulatively sum.
x
If y is a double vector, a double vector of cumulative sums, resetting whenever x is FALSE; otherwise an integer vector.
y
FALSE
If length(x) == 0, y is returned (i.e. integer(0) or double(0).
length(x) == 0
integer(0)
double(0)
# NOT RUN { cumsum_reset(c(TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE)) cumsum_reset(c(TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE), c(1000, 1000, 10000, 10, 20, 33, 0)) # }
Run the code above in your browser using DataLab