使用xts滞后定期时间序列

时间:2013-05-14 19:00:01

标签: r time-series xts zoo

我试图使用xts延迟(弱)常规时间序列。 zoo ::: lag.zooreg提供了正确的行为,但如果可能,我宁愿坚持使用xts。关于如何使用xts进行以下工作的任何建议?

#create a multivariate regular time series
tmp <- zooreg(data.frame(a=1:10,b=20:11),start=as.yearmon("2012-05-01"),frequency=12)
#july is missing
tmp <- tmp[-3,]
tmp2 <- xts(tmp)

#lag using xts. this doesn't use the weak regularity of the time-series
tmp2$lag1 <- lag(tmp2$a,1)
#what I really want is this behavior with xts (for speed, consistency, etc)
tmp3 <- merge(tmp,lag1=lag(tmp$a,-1),all=c(TRUE,FALSE))

#below is more elegant than merge, but I don't want the extra row for march
#is merge the only way to take care of this?
tmp$lag1 <- lag(tmp$a,-1)

感谢您的帮助。

0 个答案:

没有答案