[R] question on lag.zoo

From: Bo Zhou <bozhou1981_at_hotmail.com>
Date: Sun, 02 Mar 2008 14:12:49 +0000

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_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:15:58 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