[R] Cent. Mov. Ave

Ben Bolker ben at zoo.ufl.edu
Fri Feb 22 20:28:28 CET 2002


  Take a look at filter()

On Fri, 22 Feb 2002, Erin Hodgess wrote:

> Dear R People:
>
> Here is an interesting question(I think)
> Suppose I want to calculate Centered Moving Averages; i.e.
> x[1] <- ( sum(y[1:12]) )/12
> x[2] <- ( sum(y[2:13]) )/12
>
> and so on.
>
> Of course, this is easily done through loops.  However, I have
> been trying to do this more elegantly, but have failed.  I have
> tried things like
> j1 <- 1:109
> j2 <- 12:120
>
> x[1:109] <- ( sum( y[j1:j2]) )/12
>
> but it doesn't work.  (Surprise!)
>
>
> R 1.4.0 on windows.
>
>
> Any ideas would be much appreciated!
>
> Thanks!
>
> Sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> 1 Main Street
> Houston, TX 77002
> mailto: hodgess at uhddx01.dt.uh.edu
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list