r - 有美国州和领地缩写并想转换为全名
问题描述
abbr2state(openintro 库中的一个函数)不起作用,因为它似乎在美国领土上不起作用。我可以使用哪些库等?
IE
Have Want
AS American Samoa
GU Guam
... ...
如果我使用 abbr2state,它只会忽略这些地区。
解决方案
幸运的是,这(就像许多其他有用的东西一样)已经在 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
推荐阅读
- javascript - 如何迭代地址数组对象并将地址对象的状态设置为 True 或 Flase
- javascript - 列没有为移动视图正确调整大小
- scala - 优雅地停止 Spark 批处理作业
- python - 使用 python 编辑自定义选项列表字段
- angular - 是否可以根据 API 给出的数据添加或删除 dom 元素
- amazon-web-services - 似乎无法在 Ubuntu EC2 实例上打开端口 8787 或 3939,但 22 和 80 可以正常打开
- xml - 获取 log4j2.xml 中 ${catalina.base} 的值
- c# - 如何按名称动态访问类字段
- linux-kernel - Perf 跟踪并非每次运行都显示所有跟踪点
- google-cloud-dataflow - 使用 Dataflow Java 代码加入嵌套结构表