[R] Help with Moving Average in R

Berend Hasselman bhh at xs4all.nl
Mon Dec 28 08:58:20 CET 2009



Saji Ren wrote:
> 
> ...
>> MA2 = filter(x,c(rep(1/2,2),0),sides = 1)
>> MA2
>  [1]  NA  NA 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5
> 
> But what I want is:
> [1]  NA  NA 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5
> 
> And I think the command I used to get MA2 should give a result as what I
> want, but it just does not.
> I want to know the reason, and I wondor if anyone could introduce a more
> convinient way to compute that.
> 

How about

MA2 <- filter(yts,c(0,rep(0.5,2)),sides=1)

Berend
-- 
View this message in context: http://n4.nabble.com/Help-with-Moving-Average-in-R-tp989627p989645.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list