Gabor, If you follow those steps on a series with missing values, the resulting tt will contain tons of new NAs. (See my original email and the call to "zrt = as.ts(zr)".)
At any rate, I finally managed to finagle a ts with the correct frequency by coercing to ts _twice_ and specifying the frequency the second time: > z = zoo(x, order.by=t) > t = as.ts(z) > tt = ts(t, frequency=24) > frequency(tt) [1] 24 > length(tt) [1] 92064 Unfortunately, the fundamental problem appears to be with stl, because I pass it the tt object above and get this error: > stl(tt, s.window="periodic",na.action=F) Error in stl(tt, s.window = "periodic", na.action = F) : series is not periodic or has less than two periods Of course, tt is periodic (see call to frequency() above) and has more than two periods (see corresponding call to length() above), so the error is nonsense. I finally found the following email from Jeff Ryan: https://stat.ethz.ch/pipermail/r-sig-finance/2008q4/003451.html > >* stl > *function (x, s.window, s.degree = 0, t.window = NULL, t.degree = 1, > .... > x <- na.action(as.ts(x)) > if (is.matrix(x)) > stop("only univariate series are allowed") > n <- length(x) > period <- frequency(x) > if (period < 2 || n <= 2 * period) > stop("series is not periodic or has less than two periods") > > Which will result in an object of freq=1, and thus throw an error. > > Which leaves me with a perfectly valid input to stl that is being converted, by stl, into an invalid input before giving me an error. Is there some way to make this work? Is this a bug? On Wed, Jan 19, 2011 at 12:31 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > On Wed, Jan 19, 2011 at 3:07 PM, Adam Oliner <oli...@gmail.com> wrote: > > This still does not give me the desired behavior: > > > >> z = zoo(x, order.by=t, frequency=24) > >> t = as.ts(z) > > ... inserts 23 NA values between every actual value. This is not correct; > > the original data has a frequency of 24 and doesn't need one forced upon > it > > during coercion. > >> z = zoo(x, order.by=t) > >> t = as.ts(z) > > ... obviously doesn't give me a ts with frequency 24. > > > > Keep in mind that I'm trying to get a ts with frequency 24 so I can feed > it > > to stl. I haven't yet found a sequence of operations that lets me do > this. > > Any ideas? > > Its not clear what you are expecting but here is an example: > > > library(zoo) > > z <- zooreg(1001:1012, frequency = 4); z > 1(1) 1(2) 1(3) 1(4) 2(1) 2(2) 2(3) 2(4) 3(1) 3(2) 3(3) 3(4) > 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 > > frequency(z) > [1] 4 > > tt <- as.ts(z); tt > Qtr1 Qtr2 Qtr3 Qtr4 > 1 1001 1002 1003 1004 > 2 1005 1006 1007 1008 > 3 1009 1010 1011 1012 > > frequency(tt) > [1] 4 > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > -- - Adam J. Oliner [[alternative HTML version deleted]] ______________________________________________ R-help@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.