In data.table 1.12.0 new frollmean
function has been added to compute fast and exact rolling mean carefully handling NA
, NaN
and +Inf
, -Inf
values.
As there is no reproducible example in the question there is not much more to address here.
You can find more info about ?frollmean
in manual, also available online at ?frollmean
.
Examples from manual below:
library(data.table)
d = as.data.table(list(1:6/2, 3:8/4))
# rollmean of single vector and single window
frollmean(d[, V1], 3)
# multiple columns at once
frollmean(d, 3)
# multiple windows at once
frollmean(d[, .(V1)], c(3, 4))
# multiple columns and multiple windows at once
frollmean(d, c(3, 4))
## three above are embarrassingly parallel using openmp