An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080302/05fae2c1/attachment.pl
Idioms for a timeseries operation - moving window
7 messages · Bo Zhou, Gabor Grothendieck
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.
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080302/a658c1d8/attachment.pl
Time to upgrade to the latest version of zoo. You can also read it online here: http://cran.r-project.org/web/packages/zoo
On Sun, Mar 2, 2008 at 9:47 AM, Bo Zhou <bozhou1981 at hotmail.com> wrote:
Ah! Gabor is the man.
BTW I don't have zoo-faq. (I actually googled it out)
This is what I have:
Vignettes in package 'zoo':
zoo-quickref zoo Quick Reference (source, pdf)
zoo zoo: An S3 Class and Methods for Indexed
Totally Ordered Observations
(source, pdf)
It's a typical windows xp install of R 2.6.1.
Any idea why?
Cheers,
Bo
Date: Sun, 2 Mar 2008 09:40:09 -0500 From: ggrothendieck at gmail.com To: bozhou1981 at hotmail.com Subject: Re: [R] Idioms for a timeseries operation - moving window CC: r-help at r-project.org
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. ________________________________ Connect and share in new ways with Windows Live. Get it now!
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080302/dfa5d539/attachment.pl
Try: rollapply(x, 3, force) or embed(x, 3)[, 3:1]
On Sun, Mar 2, 2008 at 9:53 AM, Bo Zhou <bozhou1981 at hotmail.com> wrote:
I needed that matrix for following calculations. So I don't think roll* would work for me. Re: embed
x <- 1:10 embed (x, 3)
[,1] [,2] [,3] [1,] 3 2 1 [2,] 4 3 2 [3,] 5 4 3 [4,] 6 5 4 [5,] 7 6 5 [6,] 8 7 6 [7,] 9 8 7 [8,] 10 9 8
x
[1] 1 2 3 4 5 6 7 8 9 10 The matrix is in revered order. Anyway to put the matrix in the original order? Ie 1 2 3 2 3 4 ... Cheers, Bo
Date: Sun, 2 Mar 2008 09:40:09 -0500 From: ggrothendieck at gmail.com To: bozhou1981 at hotmail.com Subject: Re: [R] Idioms for a timeseries operation - moving window CC: r-help at r-project.org
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. ________________________________ Shed those extra pounds with MSN and The Biggest Loser! Learn more.
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080302/eecd2467/attachment.pl