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? Thank you for your time and patience. -Paul Paul Schwarz, Ph.D. Associate Director of Methodology Gartner Vendor Marketing Solutions, Custom Research +1 503 241 8036 x186
Gabor Grothendieck
2004-Sep-24 01:54 UTC
[R] "moving average" method for time series objects
Schwarz,Paul <Paul.Schwarz <at> gartner.com> writes: : : 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? : : Thank you for your time and patience. : : -Paul Check out: https://stat.ethz.ch/pipermail/r-sig-finance/2004q3/000104.html
Kjetil Brinchmann Halvorsen
2004-Sep-24 12:34 UTC
[R] "moving average" method for time series objects
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? > > >library(gregmisc) ?running test <- ts(rnorm(100)) test2 <- running(test, fun=median, width=10) length(test2) [1] 91 you want fun=mean Kjetil -- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra
Paul Schwarz <Paul.Schwarz at gartner.com> wrote:> Is there an R function for calculating moving averages of time seriesobjects? Others have replied, but here's the "simple" answer for a trailing 5-day moving average, no non-standard packages needed: R> x <- 1:20 R> filter(x, rep(1/5,5), sides=1) -- David Brahm (brahm at alum.mit.edu)