powered by
Windowed / rolling operations on a vector, with a custom function fun provided as input.
fun
rollfun(x, k, fun = "mean", ..., .idx = NULL)make_idx(k, n)
make_idx(k, n)
A vector.
integer. Width of moving window; must be an integer between one and length(x).
length(x)
character or function. The function to be applied on moving subvectors of x.
x
Additional arguments to be passed to fun.
integer. A vector of indices that can be precalculated with the function make_idx.
make_idx
integer. Length of the input vector x.
Functions roll_mean and others in package RcppRoll for a more efficient implementation of rollfun to specific values of fun.
roll_mean
rollfun
Similarly, see functions rollmean and others in package zoo and functions runmean and others in package caTools.
rollmean
runmean
# NOT RUN { set.seed(1) x <- sample(1:10) rollfun(x, k = 3) rollfun(x, k = 3, fun = max) # }
Run the code above in your browser using DataLab