为什么“你好”> 0返回TRUE?

时间:2013-06-10 18:11:10

标签: r

试一试:

"hello" > 0

我尝试使用as.numeric("hello"),但它只是给了我NA。是什么给了什么?

1 个答案:

答案 0 :(得分:13)

因为0被强制转移到"0"。见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.