[R] Definition of "lag" is opposite in ts and xts objects!

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Apr 12 05:21:24 CEST 2012


What makes you think those are the only two options?

I happen to prefer the xts convention, but there is a lot of code out there that successfully uses ts just as it is, and I can't see breaking all of that to meet an arbitrary preference of sign convention. (It isn't my decision anyway...)
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

jpm miao <miaojpm at gmail.com> wrote:

> Example:
>Will ts objects be obsolete or modified?
>
>> a                [,1]
>1983 Q1  2.747365190
>1983 Q2  2.791594762
>1983 Q3 -0.009953715
>1983 Q4 -0.015059485
>1984 Q1 -1.190061246
>1984 Q2 -0.553031799
>1984 Q3  0.686874720
>1984 Q4  0.953911035> lag(a,4)                [,1]
>1983 Q1           NA
>1983 Q2           NA
>1983 Q3           NA
>1983 Q4           NA
>1984 Q1  2.747365190
>1984 Q2  2.791594762
>1984 Q3 -0.009953715
>1984 Q4 -0.015059485> lag(as.ts(a, start=c(1983,1)),4)
>Qtr1         Qtr2         Qtr3         Qtr4
>1982  2.747365190  2.791594762 -0.009953715 -0.015059485
>1983 -1.190061246 -0.553031799  0.686874720  0.953911035
>
>	[[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.



More information about the R-help mailing list