cumsumNA {Smisc} | R Documentation |
Computes the cummulative sum of a vector without propagating NAs
cumsumNA(x)
x |
An integer or double vector |
If x
is integer, then integer addition is used. Otherwise, floating
point (double) addition is used. Elements in x
that were NA
will continue
to be NA
, but the NA
will not be propagated.
The vector of cumulative sums.
Landon Sego
# Compare to cumsum() x <- as.integer(c(5, 2, 7, 9, 0, -1)) cumsum(x) cumsumNA(x) # Now with missing values x[c(2,4)] <- NA print(x) cumsum(x) cumsumNA(x)