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
You could use RcppRoll for very quick moving averages written in C++. Just call the roll_mean function. Docs can be found here.
RcppRoll
roll_mean
Otherwise, this (slower) for loop should do the trick:
ma <- function(arr, n=15){ res = arr for(i in n:length(arr)){ res[i] = mean(arr[(i-n):i]) } res }