Skip to content
Prev 276789 / 398506 Next

window?

Like Denis said, you are asking ts to do things that don't make sense;
in particular, some of your statements suggest you don't fully
understand what window does or what its frequency argument does.
Specifically, when you set frequency = 1 in window, that doesn't mean
take a window and treat it as if it has frequency 1; rather take the
subseries corresponding to yearly observations. Since 53 is prime,
there is no regular subseries you can extract with window() other than
the original series and the yearly series.  ts objects are required to
have a frequency so statements like "now that I am taking a subset
there is no frequency" don't really make sense.

Take a look at these examples:

## Create some working data
ds.53 <- ts(rnorm(53*2), frequency=53, start=c(2000,10))
ds.48 <- ts(rnorm(48*2), frequency = 48, start = c(2000,10))

## These all work
window(ds.53, frequency = 1) # Returns elements 1 & 54 of ds.53
window(ds.53, frequency = 53) # Returns every element of ds.53

window(ds.48, frequency = 1) # Returns elements 1 & 54 of ds.53
window(ds.48, frequency = 12) # Returns elements seq(1, 48, by = 4) of ds.48
window(ds.48, frequency = 48) # Returns every element of ds.48

## These don't
window(ds.53, frequency = 7)
window(ds.48, frequency = 9)

Here's how you could do the same with xts.

library(xts)
library(forecast)
x = xts(rnorm(53*2), Sys.Date() + 365*seq(0, 2, by = 1/53))
ets(x) # Auto-conversion to ts

Michael
On Tue, Nov 8, 2011 at 8:19 PM, Kevin Burton <rkevinburton at charter.net> wrote: