Can someone explain to me what's going on here? Specifically:
- Why do I get a TRUE in the first place for the first case?
- Why does it switch to FALSE when comparing with "10"?
"9" > 2
# [1] TRUE
"10" > 2
# [1] FALSE
Can someone explain to me what's going on here? Specifically:
"9" > 2
# [1] TRUE
"10" > 2
# [1] FALSE
The hierarchy for coercion is: logical < integer < numeric < character. So in both cases, the numeric is coerced to character. Characters get "sorted" position by position in ASCII order. So "9"
is greater than "2"
but "10"
is less than "2"
because "1"
is less than "2"
.