cumsumWindow: Calculate Limited Cumulative Sum

View source: R/cumsumWindow.R

cumsumWindowR Documentation

Calculate Limited Cumulative Sum

Description

Calculate the cumulative sum of a set of numbers within a vector. The difference between this and cumsum() is that it is a sliding window approach, so sums are not necessarily calculated over the entire length of the vector. When cut == length(x) then it is the same as cumsum(). Also, for entries < window, i.e. the beginning, the entries returned will be identical to cumsum().

Usage

cumsumWindow(x, window)

Arguments

x

The vector to be summed across.

window

The length/size of the window to sum within (the moving cutoff).

Details

If window >= length(x), a warning is triggered and cumsumWindow reverts to cumsum().

Value

A vector of the sums of the sliding window for the cumulative sums.

Author(s)

Stu Field

See Also

cumsum()

Examples

cumsumWindow(1:20, 5)
cumsumWindow(1:20, window = 20)
cumsum(1:20)
r.vec <- sample(1:20, 100, replace=TRUE) # random vector
cumsumWindow(r.vec, 5)

stufield/stuRpkg documentation built on April 2, 2022, 2:05 p.m.