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

Achim Zeileis Achim.Zeileis at uibk.ac.at
Thu Apr 12 08:19:01 CEST 2012


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.
>



More information about the R-help mailing list