Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing (alphanumeric) character strings in R

Consider the following:

"16D" < "7A"

returns TRUE.

Why is that and how can I compare such character strings such that the number is compared first then the letter? This way the answer would be false because 16>7 and D>A?

like image 911
user10853 Avatar asked Oct 15 '25 13:10

user10853


1 Answers

Can you adapt this?

library("gtools")
(m <- mixedorder(c("16D","7A")))
## [1] 2 1
m[1] < m[2] ## FALSE
like image 82
Ben Bolker Avatar answered Oct 17 '25 23:10

Ben Bolker