Coercing string to int

r

Solution

I think it's doing the opposite and converting the int to a string.

> "0.0" < "14.9a"
[1] TRUE

> "2.03" < "14.9a"
[1] FALSE

> "10.11006" < "14.9a"
[1] TRUE

From the 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.

and also:

Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use: see locales. The collating sequence of locales such as en_US is normally different from C (which should use ASCII) and can be surprising. Beware of making any assumptions about the collation order ...

Problem

Can anyone explain why the following happens in R: ``` > 0.0 < "14.9a" [1] TRUE > 2.03 < "14.9a" [1] FALSE > 10.11006 < "14.9a" [1] TRUE ``` what happens when "14.9a" is coerced internally to an int? It can't just be ignoring non-numeric characters as the 2nd example shows.

Original source