rollfun: Moving windows with custom function

Description Usage Arguments See Also Examples

Description

Windowed / rolling operations on a vector, with a custom function fun provided as input.

Usage

1
2
3
rollfun(x, k, fun = "mean", ..., .idx = NULL)

make_idx(k, n)

Arguments

x

A vector.

k

integer. Width of moving window; must be an integer between one and length(x).

fun

character or function. The function to be applied on moving subvectors of x.

...

Additional arguments to be passed to fun.

.idx

integer. A vector of indices that can be precalculated with the function make_idx.

n

integer. Length of the input vector x.

See Also

Functions roll_mean and others in package RcppRoll for a more efficient implementation of rollfun to specific values of fun.

Similarly, see functions rollmean and others in package zoo and functions runmean and others in package caTools.

Examples

1
2
3
4
set.seed(1)
x <- sample(1:10)
rollfun(x, k = 3)
rollfun(x, k = 3, fun = max)

bazar documentation built on May 2, 2019, 7:02 a.m.