How to sort the string as ASCII

Viewed 41

R sorts character vectors in a sequence not ASCII

For example:

s <- c('a','Any','Aaba','b','B','Baby','Bob')

stringr::str_sort(s, locale = 'en')
[1] 'a' 'Aaba' 'Any' 'b' 'B' 'Baby' 'Bob'

How can I sort that in ASCII like this:

'Aaba' 'Any' 'B' 'Baby' 'Bob' 'a' 'b'
1 Answers

What about this?

> sort(s, method = "radix")
[1] "Aaba" "Any"  "B"    "Baby" "Bob"  "a"    "b"
Related