Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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
R 在第一列中子集包含逻辑值的xts对象失败_R_Xts - Fatal编程技术网

R 在第一列中子集包含逻辑值的xts对象失败

R 在第一列中子集包含逻辑值的xts对象失败,r,xts,R,Xts,谁能解释一下下面的R代码中发生了什么以及为什么 a <- seq(as.Date('2000-01-01'),as.Date('2001-01-01'),'day') b <- seq(as.Date('2000-01-01'),as.Date('2002-01-01'),'day') a <- as.xts(1:NROW(a),a) b <- as.xts(1:NROW(b),b) NROW(b[index(a)]) d <- b>100 NROW(d[i

谁能解释一下下面的R代码中发生了什么以及为什么

a <- seq(as.Date('2000-01-01'),as.Date('2001-01-01'),'day')
b <- seq(as.Date('2000-01-01'),as.Date('2002-01-01'),'day')
a <- as.xts(1:NROW(a),a)
b <- as.xts(1:NROW(b),b)

NROW(b[index(a)])
d <- b>100
NROW(d[index(a)])
d <- cbind(b>100,b>100)
NROW(d[index(a)])
d <- cbind(b>100,b)
NROW(d[index(a)])
d <- cbind(b,b>100)
NROW(d[index(a)])
d <- cbind(b,b)
NROW(d[index(a)])

有效,我很好奇为什么使用带有日期的向量不起作用。

看起来像个bug。逻辑运算符正在从索引中删除
tzone
属性,这导致它们略有不同。例如,比较:

> attributes(.index(b))
$tzone
[1] "UTC"

$tclass
[1] "Date"

> attributes(.index(b-1))
$tzone
[1] "UTC"

$tclass
[1] "Date"

> attributes(.index(b>1))
$tzone
[1] ""

$tclass
[1] "Date"

谢谢as.POSIXct()似乎解决了这个问题。这已在R-Forge上的r790中修复。
> attributes(.index(b))
$tzone
[1] "UTC"

$tclass
[1] "Date"

> attributes(.index(b-1))
$tzone
[1] "UTC"

$tclass
[1] "Date"

> attributes(.index(b>1))
$tzone
[1] ""

$tclass
[1] "Date"