Reputation: 3
What is the logic used by R to end up with the output FALSE in the below logical operation on characters. Is it just comparing letter S with letter T instead of the entire string.
"Sachin" > "Tendulkar"
Output: FALSE
Upvotes: 0
Views: 43
Reputation: 226532
This is in the documentation. ?">"
gives:
Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use
In other words, this is just a regular dictionary-style comparison. Things can get very complicated/weird depending on locales (e.g. how non-alphabetic, accented, upper/vs lower case, etc. etc. characters are handled), but this case looks straightforward. "S" comes before "T" in every locale I can imagine, so "S"<"T"
; in a lexicographic sort, this will determine the order (otherwise ties would be broken by later letters in the sequence).
Upvotes: 2