我正在尝试对包含美国所有不同状态的向量进行排序。但是,在使用order
函数时,R无法按正确顺序对以V或W开头的状态进行排序,而是按以下字母对它们进行排序。像这样:
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
有没有人知道发生了什么?来自arrange
的{{1}}为我提供了正确的解决方案,但我不能将其用于此问题。
dplyr