Its a FAQ. x is of class "zoo" but z is of class "zooreg" so one is using zoo.lag and the is using zooreg.lag. See question #6 in the zoo FAQ: vignette("zoo-faq") and also ?lag.zoo
On Sun, Mar 2, 2008 at 9:12 AM, Bo Zhou <[EMAIL PROTECTED]> wrote: > > Hi Guys, > > I'm using zoo package now. I found lag is not doing what I assumed. > > > x <- zoo(11:21) > > z <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4) > > x > 1 2 3 4 5 6 7 8 9 10 11 > 11 12 13 14 15 16 17 18 19 20 21 > > lag(x) > 1 2 3 4 5 6 7 8 9 10 > 12 13 14 15 16 17 18 19 20 21 > > z > 1959 Q2 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 Q2 1961 > Q3 > 1 2 3 4 5 6 7 8 9 10 > > lag(z) > 1959 Q1 1959 Q2 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 > Q2 > 1 2 3 4 5 6 7 8 9 10 > > > Why z and lag (z) are of same length while lag(x) is shorter by one than x? > > I assume lag(z) would give me like this: > 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1 1961 Q2 1961 Q3 > 2 3 4 5 6 7 8 9 10 > ie preserve the relationship between timestamp and the value. > > Same things applies to lag(x) but I guess both make sense: > 1 2 3 4 5 6 7 8 9 10 > > 12 13 14 15 16 17 18 19 20 21 > or > 2 3 4 5 6 7 8 9 10 11 > > 12 13 14 15 16 17 18 19 20 21 > > > Any insight? > > Cheers, > > Bo > > _________________________________________________________________ > [[elided Hotmail spam]] > > [[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. > ______________________________________________ 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.