Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "hello" > 0 return TRUE?

Tags:

r

Try it:

"hello" > 0

I tried using as.numeric("hello") but it just gave me back NA. What gives?

like image 815
user2407894 Avatar asked Jun 10 '13 18:06

user2407894


1 Answers

Because 0 is coerced to "0". See 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.
like image 59
Joshua Ulrich Avatar answered Sep 27 '22 20:09

Joshua Ulrich