xts 与另一个 xts 对象的比较不起作用 [英] xts comparison to another xts object does not work
问题描述
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
我知道我可以使用 coredata
来提取然后比较.我不确定这是否是错误.比较工作似乎不一致,甚至数学运算符在 xts 对象上也能正常工作,但将一个 xts 与另一个进行比较失败.
I know I can use coredata
to extract and then compare. I wasn't sure if this is bug. It didn't seem consistent that comparisons work and even math operators work just fine on xts objects but comparing one xts to another fails.
推荐答案
这与一般的时间序列一致.您无法比较(或执行任何操作)来自不同时间段的值.xts 实际上可以防止无法自然发生的行为.如果您需要将一个时期与另一个时期进行比较,则需要通过 coredata() 或使用 lag() 运算符进行强制.
This is consistent with time series in general. You can't compare (or do any Ops) on values from differing time periods. xts in effect guards against behavior that can't happen naturally. If you need to compare one period to another, you'll need to force via coredata() or by using the lag() operators.
这篇关于xts 与另一个 xts 对象的比较不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!