brain of mat kelcey...


moving average of a time series in R

June 15, 2010 at 04:15 PM | categories: Uncategorized

in this a sliding window of 3 elements

1
2
3
4
5
6
7
8
9
> x = c(3,1,4,1,5,9,2,6,5,3,5,8)
> ra_x = filter(x, rep(1,3)/3)
> ra_x
Time Series:
Start = 1 
End = 12 
Frequency = 1 
 [1]       NA 2.666667 2.000000 3.333333 5.000000 5.333333 5.666667 4.333333
 [9] 4.666667 4.333333 5.333333       NA