Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ts.intersect不适用于xts对象_R_Time Series_Xts - Fatal编程技术网

ts.intersect不适用于xts对象

ts.intersect不适用于xts对象,r,time-series,xts,R,Time Series,Xts,以下操作将产生一个错误 a1 = as.xts(ts(rnorm(20), start=c(1980,1), freq=4)) a2 = as.xts(ts(rnorm(30), start=c(1983,1), freq=4)) a = ts.intersect(a1,a2) Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = FALSE) : no time series supplied

以下操作将产生一个错误

a1 = as.xts(ts(rnorm(20), start=c(1980,1), freq=4))
a2 = as.xts(ts(rnorm(30), start=c(1983,1), freq=4))
a = ts.intersect(a1,a2)

Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = FALSE) : 
  no time series supplied
文件上说这个论点应该是正确的


两个或多个单变量或多变量时间序列,或可强制为时间序列的对象。

ts.intersect
通过查找
tsp
属性确定对象是否为
ts
对象
as.xts.ts
删除
tsp
属性,这就是为什么它不会强制返回到
ts
对象

这看起来像是xts->ts->xts转换中的一个bug,但我需要仔细看看

作为一种解决方法,您可以手动将
tsp
属性添加到xts对象(请注意,这可能会导致其他xts方法出现问题,例如
str.xts
)并添加
.tsp
属性

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 xts
a1 <- 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)
set.seed(21)

A1似乎
ts->xts->ts
错误仍然存在@Joshua难道我们在
xts包中没有等价的函数吗
,所以我们不需要在每次需要
ts
函数时来回转换吗?