Calculating moving average

前端 未结 16 1966
夕颜
夕颜 2020-11-21 23:55

I\'m trying to use R to calculate the moving average over a series of values in a matrix. The normal R mailing list search hasn\'t been very helpful though. There doesn\'t s

16条回答
  •  余生分开走
    2020-11-22 00:48

    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.

提交回复
热议问题