You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation says argument should be, "two or more univariate or multivariate time series, or objects which can coerced to time series."
My response:
ts.intersect determines whether the objects is a ts object by looking for the tsp attribute. as.xts.ts removes the tsp attribute, which is why it is not coerced back to a ts object.
This looks like a bug in xts->ts->xts conversion, but I need to take a closer look.
As a work-around, you can manually add the tsp attribute to your xts object (note that this might cause issues with other xts methods, e.g. str.xts) and add a .tsp attribute as well.
set.seed(21)
A1<- ts(rnorm(20), start=c(1980,1), freq=4)
A2<- ts(rnorm(30), start=c(1983,1), freq=4)
# convert to xtsa1<- as.xts(A1)
a2<- as.xts(A2)
# add tsp attribute# (so stats:::.cbind.ts will think these are coercible to ts objects)
tsp(a1) <- tsp(A1)
tsp(a2) <- tsp(A2)
# add .tsp attribute# (needed for as.ts.xts to work)
attr(a1,'.tsp') <- tsp(A1)
attr(a2,'.tsp') <- tsp(A2)
a<- ts.intersect(a1,a2)
The text was updated successfully, but these errors were encountered:
Taken from a Stack Overflow question:
My response:
The text was updated successfully, but these errors were encountered: