From: Whit Armstrong <whit_at_twinfieldscapital.com>

Date: Thu 03 Mar 2005 - 10:03:54 EST

Date: Thu 03 Mar 2005 - 10:03:54 EST

Thanks, everyone, for all the suggestions.

The rollFun turs out to be just what I needed.

Cheers,

Whit

-----Original Message-----

From: Kjetil Brinchmann Halvorsen [mailto:kjetil@acelerate.com]
Sent: Wednesday, March 02, 2005 5:45 PM

To: Whit Armstrong

Cc: r-help@stat.math.ethz.ch

Subject: Re: [R] apply a function to a rolling subset of a vector

>Does anyone know an easy way to calculate the rolling 20 period average

>or sum of a vector?

*>
**>For instance:
**>x <- rnorm(1000)
**>
**>y <- apply.subset(x,20,fun="sum")
**>
**>
*

help.search("rolling")

gives me (among others)

RollingAnalysis(fSeries)

Rolling Analysis

so trying

library(fSeries)

x <- rnorm(1000)

y <- rollFun(x, 20, mean)

Kjetil

>The first element of y would contain the sum of elements 1 to 20, the

*>second element of y would contain the sum of elements 2:21, and so on.
**>
**>I thought I had seen this on the list a year or so ago, but I couldn't
**>find anything in the archives.
**>
**>
**>Thanks in advance,
**>Whit
**>
**> [[alternative HTML version deleted]]
**>
**>______________________________________________
**>R-help@stat.math.ethz.ch mailing list
**>https://stat.ethz.ch/mailman/listinfo/r-help
**>PLEASE do read the posting guide!
**>http://www.R-project.org/posting-guide.html
**>
**>
**>
**>
**>
*

-- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra -- No virus found in this outgoing message. Checked by AVG Anti-Virus. ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlReceived on Thu Mar 03 10:48:15 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:30:39 EST
*