[R] How to calculate moving average without using filter()?
ruipbarradas at sapo.pt
Mon Feb 17 20:07:52 CET 2014
Many packages have a movind average function. For instance package
In your example, what you compute is not exactly a moving average, but
in can be computed with something like the following.
s <- (seq_along(dat) - 1) %/% 3
sapply(split(dat, s), mean)
Hope this helps,
Em 17-02-2014 18:45, C W escreveu:
> Hi list,
> How do I calculate a moving average without using filter(). filter() does
> not seem to give weighted averages.
> I am looking into apply(), tapply,... But nothing "moves".
> For example,
> I understand the point of apply is to avoid loops, how should I incorporate
> this idea into using an apply()?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help