rollfun {bazar}R Documentation

Moving windows with custom function

Description

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

Usage

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

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


[Package bazar version 1.0.11 Index]