如何在R中获得美国州名的缩写?

美国有五十个州,其中几个州的简称很短,但大多数州的名称都很长。因此,如果我们要处理的州名称为美国的数据,则使用州名称访问州会有点复杂,因此最好使用缩写。我们可以借助state.abb函数获得状态名称的缩写。

例子

state.abb[which(state.name=="New York")]

[1] "NY"

state.abb[which(state.name=="California")]

[1] "CA"

state.abb[which(state.name=="Texas")]

[1] "TX"

state.abb[which(state.name=="Florida")]

[1] "FL"

state.abb[which(state.name=="Washington")]

[1] "WA"

state.abb[which(state.name=="Michigan")]

[1] "MI"

state.abb[which(state.name=="New Jersey")]

[1] "NJ"

state.abb[which(state.name=="Arizona")]

[1] "AZ"

state.abb[which(state.name=="Pennsylvania")]

[1] "PA"

state.abb[which(state.name=="Alaska")]

[1] "AK"

state.abb[which(state.name=="Massachusetts")]

[1] "MA"

state.abb[which(state.name=="Ohio")]

[1] "OH"

state.abb[which(state.name=="Georgia")]

[1] "GA"

state.abb[which(state.name=="Minnesota")]

[1] "MN"

state.abb[which(state.name=="Hawaii")]

[1] "HI"

state.abb[which(state.name=="Illinois")]

[1] "IL"

state.abb[which(state.name=="Colorado")]

[1] "CO"

state.abb[which(state.name=="North Carolina")]

[1] "NC"

state.abb[which(state.name=="Virginia")]

[1] "VA"

state.abb[which(state.name=="Alabama")]

[1] "AL"

state.abb[which(state.name=="Oregon")]

[1] "OR"

state.abb[which(state.name=="Indiana")]

[1] "IN"

state.abb[which(state.name=="Maryland")]

[1] "MD"

state.abb[which(state.name=="Missouri")]

[1] "MO"

state.abb[which(state.name=="Tennessee")]

[1] "TN"

state.abb[which(state.name=="Wisconsin")]

[1] "WI"

state.abb[which(state.name=="Montana")]

[1] "MT"

state.abb[which(state.name=="South Carolina")]

[1] "SC"

state.abb[which(state.name=="Maine")]

[1] "ME"

state.abb[which(state.name=="Utah")]

[1] "UT"

state.abb[which(state.name=="Connecticut")]

[1] "CT"

state.abb[which(state.name=="Mississippi")]

[1] "MS"

state.abb[which(state.name=="Wyoming")]

[1] "WY"

state.abb[which(state.name=="Iowa")]

[1] "IA"

state.abb[which(state.name=="Louisiana")]

[1] "LA"

state.abb[which(state.name=="Kentucky")]

[1] "KY"

state.abb[which(state.name=="Nevada")]

[1] "NV"

state.abb[which(state.name=="Rhode Island")]

[1] "RI"

state.abb[which(state.name=="Arkansas")]

[1] "AR"

state.abb[which(state.name=="New Mexico")]

[1] "NM"

state.abb[which(state.name=="Idaho")]

[1] "ID"

state.abb[which(state.name=="Delaware")]

[1] "DE"

state.abb[which(state.name=="Nebraska")]

[1] "NE"

state.abb[which(state.name=="Kansas")]

[1] "KS"

state.abb[which(state.name=="Vermont")]

[1] "VT"

state.abb[which(state.name=="New Hampshire")]

[1] "NH"

state.abb[which(state.name=="South Dakota")]

[1] "SD"

state.abb[which(state.name=="Oklahoma")]

[1] "OK"

state.abb[which(state.name=="West Virginia")]

[1] "WV"

state.abb[which(state.name=="North Dakota")]

[1] "ND"

以上是 如何在R中获得美国州名的缩写? 的全部内容, 来源链接: utcz.com/z/331421.html

回到顶部