R 在第一列中子集包含逻辑值的xts对象失败
谁能解释一下下面的R代码中发生了什么以及为什么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
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"