r - Lagging regular time series with xts -
i trying lag (weakly) regular time series using xts. zoo:::lag.zooreg provides correct behavior, prefer stick xts if possible. suggestions on how make below work xts?
#create multivariate regular time series tmp <- zooreg(data.frame(a=1:10,b=20:11),start=as.yearmon("2012-05-01"),frequency=12) #july missing tmp <- tmp[-3,] tmp2 <- xts(tmp) #lag using xts. doesn't use weak regularity of time-series tmp2$lag1 <- lag(tmp2$a,1) #what want behavior xts (for speed, consistency, etc) tmp3 <- merge(tmp,lag1=lag(tmp$a,-1),all=c(true,false)) #below more elegant merge, don't want row march #is merge way take care of this? tmp$lag1 <- lag(tmp$a,-1)
thanks help.
Comments
Post a Comment