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 comparing two variables not only when they are not equal but also when their type is not same.
For example :
7 == "7"
var1 = 8 == "8"
var2 = typeof(8) == typeof("8")
var1 & var2
?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
!= for tests in
if-expressions. They recommend using
7 == "7" # TRUE identical(7, "7") # FALSE