Learn R Programming

runner (version 0.2.1)

mean_run: Running mean

Description

Running mean

Usage

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

Arguments

x

vector of any type on which running mean is calculated

k

running window size. Not yet implemented.

na_rm

logical (default na_rm=TRUE) - if TRUE mean 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 mean 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)
mean_run(x1)
mean_run(x2, na_rm = TRUE)
mean_run(x2, na_rm = FALSE )
mean_run(x2, na_rm = TRUE, k=4)
# }

Run the code above in your browser using DataLab