Learn R Programming

quickcode (version 1.0.6)

na.cumsum: Cumulative Sum with NA Removal

Description

This function calculates the cumulative sum of a numeric vector, removing any `NA` values before computation.

Usage

na.cumsum(x)

Value

A numeric vector representing the cumulative sum with `NA` values removed. Returns an empty vector if the input is empty or contains only `NA` values.

Arguments

x

A numeric vector for which the cumulative sum is to be calculated.

Examples

Run this code
# Example with numeric vector
numeric_vector <- c(1, 2, NA, 4, 5)
na.cumsum(numeric_vector)

# Example with all NAs
na.cumsum(c(NA, NA))

Run the code above in your browser using DataLab