Why doesn't comparison between numeric and character variables give a warning?

后端 未结 1 1014
深忆病人
深忆病人 2020-12-10 12:24

I had a bug in my code resulting from an inadvertent comparison between a character variable and a numeric variable (they were both supposed to be numeric). This bug would h

相关标签:
1条回答
  • 2020-12-10 13:04

    In your example 5 is converted to a character, so the test is the same as 'two' < as.character(5).

    From ?Comparison:

    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.

    0 讨论(0)
提交回复
热议问题