Learn R Programming

Smisc (version 0.3.9.1)

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

Description

Computes the cummulative sum of a vector without propagating NAs

Usage

cumsumNA(x)

Arguments

x

An integer or double vector

Value

The vector of cumulative sums.

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.

See Also

cumsum

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab