首页 > 解决方案 > 有美国州和领地缩写并想转换为全名

问题描述

abbr2state(openintro 库中的一个函数)不起作用,因为它似乎在美国领土上不起作用。我可以使用哪些库等?

IE

   Have    Want
    AS      American Samoa 
    GU      Guam 
    ...     ...

如果我使用 abbr2state,它只会忽略这些地区。

标签: r

解决方案


幸运的是,这(就像许多其他有用的东西一样)已经在 R 中实现。

cbind(state.abb,state.name)

会给你你想要的输出

     state.abb state.name  
[1,] "AL"      "Alabama"   
[2,] "AK"      "Alaska"    
[3,] "AZ"      "Arizona"   
[4,] "AR"      "Arkansas"  
[5,] "CA"      "California"
[6,] "CO"      "Colorado"  

编辑::

还可以获得可以使用 USAboundaries 包的地区:

install.packages('USAboundaries')
library(USAboundaries)

#lookuptable territorys :

state_codes[state_codes$jurisdiction_type == "territory",]

#state_name                     state_abbr state_code jurisdiction_type
# <chr>                          <chr>      <chr>      <chr>            
 #1 American Samoa                 "AS"       60         territory        
 #2 Federated States of Micronesia "FM"       64         territory        
 #3 Guam                           "GU"       66         territory        
 #4 Johnson Atoll                  ""         67         territory        
 #5 Marshall Islands               "MH"       68         territory        
 #6 Northern Mariana Islands       "MP"       69         territory        
 #7 Palau                          "PW"       70         territory        
 #8 Midway Islands                 ""         71         territory        
 #9 Puerto Rico                    "PR"       72         territory  


推荐阅读