cumsum_reset {hutilscpp} | R Documentation |
Cumulative sum unless reset
Description
Cumulative sum unless reset
Usage
cumsum_reset(x, y = as.integer(x))
Arguments
x |
A logical vector indicating when the sum should continue.
Missing values in |
y |
Optional: a numeric vector the same length as |
Value
A vector of cumulative sums,
resetting whenever x
is FALSE
.
The return type is double if y
is double; otherwise an integer vector. Integer
overflow wraps around, rather than being promoted to double type, as this
function is intended for 'shortish' runs of cumulative sums.
If length(x) == 0
, y
is returned (i.e. integer(0)
or double(0)
.
Examples
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))
[Package hutilscpp version 0.10.5 Index]