why is “” == true in R

前端 未结 1 468
星月不相逢
星月不相逢 2021-01-19 05:14

I just started learning R and in my first assignment, I face a problem where I need to compare a bunch of variables and while doing that I am supposed to get false when comp

相关标签:
1条回答
  • 2021-01-19 05:51

    From the ?Comparison help page:

    If the two arguments are atomic vectors of different types, one is coerced to the type of the other, the (decreasing) order of precedence being character, complex, numeric, integer, logical and raw.

    On the same help page, the authors warn for using == and != for tests in if-expressions. They recommend using identical() instead:

    7 == "7"
    # TRUE
    identical(7, "7")
    # FALSE
    
    0 讨论(0)
提交回复
热议问题