[R] Definition of "lag" is opposite in ts and xts objects!
R. Michael Weylandt
michael.weylandt at gmail.com
Thu Apr 12 05:17:20 CEST 2012
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.
More information about the R-help
mailing list