Is there a way to apply a function to the n column values above within each group? I would like to calculate the standard deviation of the 24 values above and I'm looking for a function like the lag operator but this lag should be applied to 24 lags (at once).
data <- mutate(data, vola = sd(lag(return,1:24)))
Is there an appropriate dplyr function? thanks in advance