For a series
X=(x_1,x_2,...x_t-2, x_t-1, x_t)
I would like to compute a moving average for each point with respect to the previous k time steps. For example, if k = 2, I want to return:
X =(NA, (x_1+x_2)/2 ... (x_t-2 + x_t-3)/2, (x_t-2 + x_t-1)/2, (x_t + x_t-1)/2)
If I use the moving average function ma, e.g.
ma(X, order = 2, centre = TRUE)
I get the average of each point and its neighbor in the positive and negative direction, while setting centre=FALSE calculates the moving average with respect to the positive direction. Is there a simple way to have point t as the running average of (t-k+1...t)?