Re: [R] question on lag.zoo

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 02 Mar 2008 09:33:00 -0500

On Sun, Mar 2, 2008 at 9:28 AM, Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote:
> Its a FAQ. x is of class "zoo" but z is of class "zooreg" so one is using

That should be lag.zooreg

> 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 <bozhou1981_at_hotmail.com> 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_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.
> >
>



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:44:01 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