Learn R Programming

runner (version 0.2.1)

sum_run: Running sum

Description

Running sum in specified window of numeric vector.

Usage

sum_run(x, k = 0L, na_rm = TRUE, na_pad = FALSE, idx = 1L)

Arguments

x

vector of any type where running sum is calculated

k

Running window size. Not yet implemented.

na_rm

logical (default na_rm=TRUE) - if TRUE sum is calulating excluding NA.

na_pad

logical (default na_pad=FALSE) - if TRUE first k-results will be filled by NA. If k is not specified na_pad=F by default.

idx

an optional integer vector containing idx numbers of observation.

Value

numeric vector of length equals length of x containing running sum in k-long window.

Examples

Run this code
# NOT RUN {
set.seed(11)
x1 <- rnorm(15)
x2 <- sample(c(rep(NA,5),rnorm(15)), 15, replace=TRUE)
k <- sample(1:15, 15, replace=TRUE)
sum_run(x1)
sum_run(x2, na_rm = TRUE)
sum_run(x2, na_rm = FALSE )
sum_run(x2, na_rm = TRUE, k=4)
# }

Run the code above in your browser using DataLab