0

I have two objects of class 'times' generated using chron that I am trying to compare. On the surface they look identical:

   > str(x)
    Class 'times'  atomic [1:6] 0.04444 0.05417 0.05486 0.00208 0.01111 ...
    ..- attr(*, "format")= chr "h:m:s"
   > str(y)
    Class 'times'  atomic [1:6] 0.04444 0.05417 0.05486 0.00208 0.01111 ...
    ..- attr(*, "format")= chr "h:m:s"

So I expected that x - y = 0 or x==y would return TRUE, but this is not the case:

    > x-y
    [1] -6.245005e-17 -2.775558e-17 -2.775558e-17  7.372575e-18 -7.112366e-17  0.000000e+00
    > x==y
    [1] FALSE FALSE FALSE FALSE FALSE  TRUE

Any idea what is going on or how I can compare the two? I already tried changing it to POSIXct and that works, but before comparing, I have operations to do on the data frame columns this data comes from (adding and subtracting), which can't be done with POSIXct. Also, it requires extra steps and this is meant to be a quick check up to see if there are any discrepencies in the data.

I guess I can use as.character(x)==as.character(y), and it works, but there has to be a more elegant way of doing this...

lcabral
  • 25
  • 7
  • Sounds similar to this old chestnut - http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal like problem? – thelatemail Apr 07 '17 at 03:01
  • Can you use all.equal() in that case? – Edgar Santos Apr 07 '17 at 04:15
  • Thanks @thelatemail. That does work, although I run into a problem if the result is that there is a difference. I can't pinpoint what rows show a difference... Any suggestions? Should I apply the all.equal on each row? That doesn't seem very efficient.... – lcabral Apr 07 '17 at 16:10

0 Answers0