2

"1" is character value and other 1 is numeric. Even, when I tried executing below line it gave me TRUE.

as.character("0")==as.numeric(0)

Can anyone help me to understand, why?

RLave
  • 8,144
  • 3
  • 21
  • 37
Rushabh Patel
  • 2,672
  • 13
  • 34
  • 2
    `?==` says: "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." – Jaccar Feb 15 '19 at 13:47
  • 3
    answer 'why' is already given.. If you want to test, you can use `identical(as.character("0"),as.numeric(0))`, which results in `FALSE` – Wimpel Feb 15 '19 at 13:51

1 Answers1

5

From the help("=="):

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.

So 1 should be converted to "1".

RLave
  • 8,144
  • 3
  • 21
  • 37