What is the best (fastest) way to implement a sliding window function with the data.table package?
I\'m trying to calculate a rolling median but have multiple rows p
I address this in a related thread: https://stackoverflow.com/a/62399700/7115566
I suggest looking into the frollapply
function. For instance, see below
library(data.table)
set.seed(17)
dt <- data.table(i = 1:100,
x = sample(1:10, 100, replace = T),
y = sample(1:10, 100, replace = T))
dt$index <- dt$x == dt$y
dt[,`:=` (MA = frollapply(index,10,mean)), ]
head(dt,12)