Lexicographic sorting

Strings are sorted lexicographically, so could someone please explain why
"A" < "a"
is false, but
"Am" < "aMc"
is true?
Thanks

# Raw vectors should not really be considered to have an order, but the numeric order of the byte representation is used.

u <- "a"
(v <- charToRaw(u))
#> [1] 61
is.vector(u)
#> [1] TRUE

w <- "A"
(z <- charToRaw(w))
#> [1] 41
is.vector(z) 
#> [1] TRUE

x <- "aMc"
(y <- charToRaw(x))
#> [1] 61 4d 63
is.vector(y) 
#> [1] TRUE

Then why is "A" < "a" false? Isn't 41 < 61??

Yeah, it's weird until sussing byte order

If you compare lex'lly, you compare character by character, so both should be true of both false, what's byte order have to do with this?

Raw vectors should not really be considered to have an order, but the numeric order of the byte representation is used.

See docs for base::comparison

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.