Re: [R] How to calculate moving average without using filter()?

2014-02-18 Thread C W
Thanks everyone. For 5 point moving average, filter(x, side=2, filter=rep(1/5, 5)), versus, filter(x, side=2, filter=rep(1, 5) Do they have the same effect, since the total needs to be 1. Gabor & Rui: I am aware of the zoo package, I did not want to install a package for one function. Same reas

Re: [R] How to calculate moving average without using filter()?

2014-02-17 Thread Rui Barradas
Hello, Many packages have a movind average function. For instance package forecast. Or library(sos) findFn("moving average") 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(s

Re: [R] How to calculate moving average without using filter()?

2014-02-17 Thread David Winsemius
On Feb 17, 2014, at 10:45 AM, C W wrote: > 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, > > dat<-c(1:20) > mean(dat[1:3]) > mean(dat[4:

Re: [R] How to calculate moving average without using filter()?

2014-02-17 Thread Bert Gunter
There are a zillion answers to this, because your question is really: How do I smooth a time series? So you can search on appropriate keywords. My answer is: don't use moving averages -- that's pathetically ancient. ?loess is one among the zillions of alternatives you might consider. Post on CV (s

[R] How to calculate moving average without using filter()?

2014-02-17 Thread C W
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, dat<-c(1:20) mean(dat[1:3]) mean(dat[4:6]) mean(dat[7:9]) mean(dat[10:12]) etc... I understand the poi