[R] "moving average" method for time series objects
Martin Maechler
maechler at stat.math.ethz.ch
Fri Sep 24 23:53:08 CEST 2004
>>>>> "Kjetil" == Kjetil Brinchmann Halvorsen <kjetil at acelerate.com>
>>>>> on Fri, 24 Sep 2004 08:34:19 -0400 writes:
Kjetil> Schwarz,Paul wrote:
>> Dear R-Help readers,
>>
>> I suspect that this question must be a FAQ, but my
>> investigation of the archives has not been very
>> revealing. Is there an R function for calculating moving
>> averages of time series objects?
>>
>>
>>
Kjetil> library(gregmisc) ?running test <- ts(rnorm(100))
Kjetil> test2 <- running(test, fun=median, width=10)
Kjetil> length(test2) [1] 91
Kjetil> you want fun=mean
Note that really for
- running mean, you should use filter()
- running median, you use runmed()
Greg's running() function is probably appropriate for anything
else *but* these two cases...
Martin Maechler
More information about the R-help
mailing list