I'm trying to sort a vector containing all the different states of America. However, when using the order
function, R fails to order those states that start with V or W in the correct order, instead sorting them by the following letter. Like this:
first.states <- c("AL", "AR", "CA", "CO", "AZ", "AK", "CT")
first.states[order(first.states)]
[1] "AK" "AL" "AR" "AZ" "CA" "CO" "CT" #Very good!
last.states <- c("WA", "VA", "WY", "WI", "VT", "WV", "VI")
last.states[order(last.states)]
[1] "VA" "WA" "VI" "WI" "VT" "WV" "WY" #Sad face
Does anybody have a clue about what's happening? arrange
from dplyr
gives me the correct solution, but I cannot use it for this problem.
Sys.getlocale()
[1] "LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252"