cumsumNA: Computes the cummulative sum of a vector without propagating...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/cumsumNA.R

Description

Computes the cummulative sum of a vector without propagating NAs

Usage

1

Arguments

x

An integer or double vector

Details

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.

Value

The vector of cumulative sums.

Author(s)

Landon Sego

See Also

cumsum

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 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)

Example output

[1]  5  7 14 23 23 22
[1]  5  7 14 23 23 22
[1]  5 NA  7 NA  0 -1
[1]  5 NA NA NA NA NA
[1]  5 NA 12 NA 12 11

Smisc documentation built on May 2, 2019, 2:46 a.m.