rollsum: Calculate rolling sums

View source: R/utils.R

rollsumR Documentation

Calculate rolling sums

Description

Compared with zoo::rollsum(), this function is implemented in C and is one magnitude faster.

Usage

rollsum(
  x,
  k,
  na_pad = FALSE,
  na.rm = FALSE,
  align = c("center", "left", "right")
)

Arguments

x

A numeric vector.

k

integer width of the rolling window.

na_pad

Logical value about whether to pad left/right ends with NAs.

na.rm

Similar to na.rm in base::sum(), a logical value indicating whether NA values should be stripped before the computation proceeds.

align

Character specifying whether the index of the result should be left- or right-aligned or centered (default) compared to the rolling window of observations.

Value

The rolling sum.

See Also

zoo::rollsum()

Examples


x <- 1:10

# Basic usage
rollsum(x, k = 3)

# Align at the right end, and use NA for padding
rollsum(x, k = 3, na_pad = TRUE, align = "right")

haizi-zh/bedtorch documentation built on July 1, 2022, 10:40 a.m.