Skip to contents

Computes cumulative sums with options for handling missing values (NA), including linear interpolation between existing values.

Usage

hsaCumsum(x, na.action = "interpolate")

Arguments

x

Numeric vector for which to compute cumulative sums

na.action

Character or numeric specifying NA handling:

  • "interpolate": Linearly interpolates missing values (default)

  • numeric value: Replaces NAs with specified value

  • any other value: Uses base cumsum() with NAs propagating

Value

Numeric vector of cumulative sums with same length as x:

  • NAs at start/end remain after warning

  • Interpolated values for internal NAs when na.action="interpolate"

Details

For na.action="interpolate":

  • Uses linear interpolation via stats::approx()

  • Leading/trailing NAs are set to 0 with warning

  • Returns NA for positions where input was NA

See also

approx for interpolation method

Examples

x <- c(1, 2, NA, 4, 5, NA, 7)

# With interpolation
hsaCumsum(x) 
#> [1]  1  3  6 10 15 21 28

# With NA replacement
hsaCumsum(x, na.action=0)
#> [1]  1  3  3  7 12 12 19