# Xts object comparison

Trying to compare xts objects, wanted to ensure that Ret and Ret2 columns are the same.

    head(rts.fut)
Open  High   Low Close Close.prev        Ret       Ret2
2015-01-05 78450 78450 72470 73100         NA         NA         NA
2015-01-06 73230 74900 71000 72760      73100 -0.4651163 -0.4651163
2015-01-08 72800 81380 72800 80190      72760 10.2116548 10.2116548
2015-01-09 80190 81050 74450 77330      80190 -3.5665295 -3.5665295
2015-01-12 77140 77140 73180 74490      77330 -3.6725721 -3.6725721
2015-01-13 74230 74230 70870 73470      74490 -1.3693113 -1.3693113


Results:

 > head(rts.fut$Ret)==head(rts.fut$Ret2)
Ret
2015-01-05    NA
2015-01-06 FALSE
2015-01-08 FALSE
2015-01-09 FALSE
2015-01-12 FALSE
2015-01-13 FALSE


Any help will be highly appreciated,
Thanks,

• Where does your rts.fut come from? How can we confirm this if you don't give us a reproducible example? Also there are many more R experts on StackOverflow than there are here, so for simple R questions you will do better posting there. – Spacedman Jul 28 '16 at 22:08

This is not necessary related to xts. You are comparing to floating point values. As pointer out in this excellent resource these type of comparisons are dangerous. Best way to code it if you do not have Inf, -Inf or NaN is by doing,

(abs(rts.fut$Ret - rts.fut$Ret2) / pmin(abs(rts.fut$Ret) + abs(rts.fut$Ret2),
.Machine$double.eps)) < .Machine$double.eps


Hope this helps.