hutilscpp (version 0.1.0)

cumsum_reset: 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.

y

Optional: a numeric vector the same length as x to cumulatively sum.

Value

If y is a double vector, a double vector of cumulative sums, resetting whenever x is FALSE; otherwise an integer vector.

If length(x) == 0, y is returned (i.e. integer(0) or double(0).

Examples

Run this code
# 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 DataCamp Workspace