xts与另一个xts对象的比较不起作用

Pau*_*uly 3 r xts

this =
  structure(c(-0.012, -0.028, -0.044, -0.033, -0.039, -0.042), .Dim = c(3L, 2L),
  .Dimnames = list(NULL, c("one", "two")), index = structure(
  c(1313643600, 1313730000, 1313816400), tzone = "", tclass = "Date"),
  .indexCLASS = "Date", .indexTZ = "", class = c("xts", "zoo"))

m1=last(this$one) - last(this$two)
m2=first(last(this$one,n=2)) - first(last(this$two,n=2))

m1 > 0 #returns a TRUE OR FALSE
m1 > m2 #breaks
Run Code Online (Sandbox Code Playgroud)

我知道我可以coredata用来提取然后比较.我不确定这是不是错误.比较工作似乎不一致,甚至数学运算符在xts对象上工作得很好但是将xts与另一个xts进行比较失败.

Jos*_*ich 5

xts逻辑运算符就像xts数学运算符一样工作.如果两个参数都是xts对象,则两个参数的索引值必须匹配.在您的情况下,m1m2具有不同的索引值.

m1 > 0
#              one
# 2011-08-20 FALSE
m1 > m2
#     [,1]
m1
#               one
# 2011-08-20 -0.002
m2
#              one
# 2011-08-19 0.011
Run Code Online (Sandbox Code Playgroud)


Jef*_*f R 5

这与一般的时间序列一致.您无法比较(或执行任何操作)来自不同时间段的值.xts实际上可以防止不能自然发生的行为.如果你需要比较一个时期,你需要强制通过coredata()或使用lag()运算符.