Re: [R] Idioms for a timeseries operation - moving window

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 02 Mar 2008 09:40:09 -0500

See

?embed

and from zoo see:

?rollapply
?rollmean
?rollmax

There is a function coded in C in the caTools package for speed.

On Sun, Mar 2, 2008 at 9:24 AM, Bo Zhou <bozhou1981_at_hotmail.com> wrote:
>
> Hi Guys,
>
> Need your wisdom on this.
>
> Say I have a time series (in zoo format) like this
>
>
> > x <- zoo(11:21)
> > x
> 1 2 3 4 5 6 7 8 9 10 11
> 11 12 13 14 15 16 17 18 19 20 21
>
>
> I want to do a "moving window sampling" of it. The result can either be a matrix or a dataframe like this
>
> my.super.moving.window(x, length=3, by=1)
>
> 11 12 13
> 12 13 14
> 13 14 15
> 14 15 16
> ....
> 18 19 20
> 19 20 21
>
> This shouldn't be new. Many many people must have done this before. Any idea what's the best(efficient and elegant) way to do this?
>
> Cheers,
>
> Bo
>
>
>
>
> _________________________________________________________________
> Climb to the top of the charts! Play the word scramble challenge with star power.
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 02 Mar 2008 - 14:52:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 02 Mar 2008 - 15:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive