Comparison of alphanumeric characters in R

Consider the following:

"16D" < "7A"

      

returns TRUE.

Why is this and how can I compare character strings like this so that the number is compared first and then the letter? So the answer will be false because 16> 7 and D> A?

+3


source to share


1 answer


Can you adapt this?



library("gtools")
(m <- mixedorder(c("16D","7A")))
## [1] 2 1
m[1] < m[2] ## FALSE

      

+5


source







All Articles