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]]
BTW, zoo is like ts in the application of lag. In other words, zoo and xts are opposite in this issue. 2012/4/12 jpm miao <miaojpm@gmail.com>> 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. Michael Weylandt
2012-Apr-12 03:17 UTC
[R] Definition of "lag" is opposite in ts and xts objects!
Yes, this is as documented. See ? lag.xts under details for the justification and how to change the default if desired. Michael On Wed, Apr 11, 2012 at 11:13 PM, jpm miao <miaojpm at gmail.com> wrote:> BTW, zoo is like ts in the application of lag. > In other words, zoo and xts are opposite in this issue. > > 2012/4/12 jpm miao <miaojpm at gmail.com> > >> ?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.
Jeff Newmiller
2012-Apr-12 03:21 UTC
[R] Definition of "lag" is opposite in ts and xts objects!
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.
Achim Zeileis
2012-Apr-12 06:19 UTC
[R] Definition of "lag" is opposite in ts and xts objects!
On Thu, 12 Apr 2012, jpm miao wrote:> Example: > Will ts objects be obsolete or modified?No, I don't think so.>> 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. >