Calculating moving average

前端 未结 16 1809
夕颜
夕颜 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:23

    Though a bit slow but you can also use zoo::rollapply to perform calculations on matrices.

    reqd_ma <- rollapply(x, FUN = mean, width = n)
    

    where x is the data set, FUN = mean is the function; you can also change it to min, max, sd etc and width is the rolling window.

提交回复
热议问题