Lets say I have simple DT:
library(data.table)
DT <- data.table(x = 1:20)
I want to apply frollapply function on specific rows of the DT. For exmaple this code applies function on every row:
DT[, frollapply(x, n = 10, FUN = function(y) sum(y, na.rm = TRUE))]
but I want to return only 11 and 13, that is, numbers 65 and 85.
I know I can subset AFTER I applied frollapply, but than I will execute the function on every row.
Something like this doesn't work (it seems it first subset and than apply):
DT[c(11, 13), frollapply(x, n = 10, FUN = function(y) sum(y, na.rm = TRUE))]