Calculating moving average
- Rolling Means/Maximums/Medians in the zoo package (rollmean)
- MovingAverages in TTR
- ma in forecast
Or you can simply calculate it using filter, here's the function I use:
ma <- function(x, n = 5){filter(x, rep(1 / n, n), sides = 2)}
If you use dplyr
, be careful to specify stats::filter
in the function above.