rollfun {bazar} | R Documentation |
Windowed / rolling operations on a vector, with a custom function fun
provided as input.
rollfun(x, k, fun = "mean", ..., .idx = NULL)
make_idx(k, n)
x |
A vector. |
k |
integer. Width of moving window; must be an integer between one and
|
fun |
character or function. The function to be applied on moving subvectors of
|
... |
Additional arguments to be passed to |
.idx |
integer. A vector of indices that can be precalculated with the function
|
n |
integer. Length of the input vector |
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.
set.seed(1)
x <- sample(1:10)
rollfun(x, k = 3)
rollfun(x, k = 3, fun = max)