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

Forcing a string to int

Can someone 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 forcibly injected into an int? It cannot just ignore non-numeric characters, as the second example shows.

+3
source share
2 answers

I think it does the opposite and converts int to string.

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

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

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

On the help page:

If two arguments are atomic vectors of different types, forcing the type of another, (decreasing) order of priority to be a symbol, complex, numerical, integer, logical and unprocessed.

and:

, : . . , en_US, C ( ASCII) . - ...

+14

?"<":

, , () - , , , , .

, . (I.e., "2" > "10" )

+5

All Articles