R:仅从街道名称、城市和州获取邮政编码
R: Get zipcode from just Street Name, City, and State
我有一个数据集,其中包含与不同城市和州的房产相关的信息。它目前看起来像这样:
Id| StreetName | City | State
=================================================
1 | 100 Railroad Ave | Elkton | MD
2 | 414 Grant St | Pittsburgh | PA
3 | 1400 John F Kennedy Blvd | Philadelphia | PA
4 | 800 N French St | Wilmington | DE
r 中是否有可用于获取每行邮政编码的包?我想根据邮政编码创建密度图。我当前的数据包括数千行。
这是可能的,但需要美国邮政服务的(免费且简单)帐户。
使用 rusps 包(更多信息:https://github.com/hansthompson/rusps)
输出有点重复,函数似乎无法通过管道传输,但它对您发布的数据运行良好。清理 % 连接到您的数据(或单独使用)应该不会太难。
addresses <- tibble::tribble(
~Id, ~StreetName, ~City, ~State,
1, "100 Railroad Ave", "Elkton", "MD",
2, "414 Grant St", "Pittsburgh", "PA",
3, "1400 John F Kennedy Blvd", "Philadelphia", "PA",
4, "800 N French St", "Wilmington", "DE"
)
# devtools::install_github('hansthompson/rusps')
library(rusps)
library(XML)
username <- 'XXXYYYYYZZZZ' # get this quickly and freely
#by signing up at https://registration.shippingapis.com/ (not commercial).
output <- validate_address_usps(street = addresses$StreetName,
city = addresses$City,
state = addresses$State,
username = username)
output
Address2 City State Zip5 Zip4 .attrs
1 100 RAILROAD AVE ELKTON MD 21921 5537 0
2 414 GRANT ST PITTSBURGH PA 15219 2409 1
3 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 2
4 800 N FRENCH ST WILMINGTON DE 19801 3594 3
5 NA NA NA NA NA 0
6 100 RAILROAD AVE ELKTON MD 21921 5537 0
7 414 GRANT ST PITTSBURGH PA 15219 2409 0
8 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 0
9 100 RAILROAD AVE ELKTON MD 21921 5537 1
10 414 GRANT ST PITTSBURGH PA 15219 2409 1
11 100 RAILROAD AVE ELKTON MD 21921 5537 0
12 414 GRANT ST PITTSBURGH PA 15219 2409 0
13 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 0
14 800 N FRENCH ST WILMINGTON DE 19801 3594 0
出于某种原因,所有返回的列都是列表列。要清理它:
unnest(output, cols = everything()) %>%
group_by(Address2) %>%
slice(1)
# A tibble: 5 x 6
# Groups: Address2 [5]
Address2 City State Zip5 Zip4 .attrs
<chr> <chr> <chr> <chr> <chr> <chr>
1 100 RAILROAD AVE ELKTON MD 21921 5537 0
2 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 2
3 414 GRANT ST PITTSBURGH PA 15219 2409 1
4 800 N FRENCH ST WILMINGTON DE 19801 3594 3
5 NA NA NA NA NA 0
我有一个数据集,其中包含与不同城市和州的房产相关的信息。它目前看起来像这样:
Id| StreetName | City | State
=================================================
1 | 100 Railroad Ave | Elkton | MD
2 | 414 Grant St | Pittsburgh | PA
3 | 1400 John F Kennedy Blvd | Philadelphia | PA
4 | 800 N French St | Wilmington | DE
r 中是否有可用于获取每行邮政编码的包?我想根据邮政编码创建密度图。我当前的数据包括数千行。
这是可能的,但需要美国邮政服务的(免费且简单)帐户。
使用 rusps 包(更多信息:https://github.com/hansthompson/rusps)
输出有点重复,函数似乎无法通过管道传输,但它对您发布的数据运行良好。清理 % 连接到您的数据(或单独使用)应该不会太难。
addresses <- tibble::tribble(
~Id, ~StreetName, ~City, ~State,
1, "100 Railroad Ave", "Elkton", "MD",
2, "414 Grant St", "Pittsburgh", "PA",
3, "1400 John F Kennedy Blvd", "Philadelphia", "PA",
4, "800 N French St", "Wilmington", "DE"
)
# devtools::install_github('hansthompson/rusps')
library(rusps)
library(XML)
username <- 'XXXYYYYYZZZZ' # get this quickly and freely
#by signing up at https://registration.shippingapis.com/ (not commercial).
output <- validate_address_usps(street = addresses$StreetName,
city = addresses$City,
state = addresses$State,
username = username)
output
Address2 City State Zip5 Zip4 .attrs
1 100 RAILROAD AVE ELKTON MD 21921 5537 0
2 414 GRANT ST PITTSBURGH PA 15219 2409 1
3 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 2
4 800 N FRENCH ST WILMINGTON DE 19801 3594 3
5 NA NA NA NA NA 0
6 100 RAILROAD AVE ELKTON MD 21921 5537 0
7 414 GRANT ST PITTSBURGH PA 15219 2409 0
8 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 0
9 100 RAILROAD AVE ELKTON MD 21921 5537 1
10 414 GRANT ST PITTSBURGH PA 15219 2409 1
11 100 RAILROAD AVE ELKTON MD 21921 5537 0
12 414 GRANT ST PITTSBURGH PA 15219 2409 0
13 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 0
14 800 N FRENCH ST WILMINGTON DE 19801 3594 0
出于某种原因,所有返回的列都是列表列。要清理它:
unnest(output, cols = everything()) %>%
group_by(Address2) %>%
slice(1)
# A tibble: 5 x 6
# Groups: Address2 [5]
Address2 City State Zip5 Zip4 .attrs
<chr> <chr> <chr> <chr> <chr> <chr>
1 100 RAILROAD AVE ELKTON MD 21921 5537 0
2 1400 JOHN F KENNEDY BLVD PHILADELPHIA PA 19107 3200 2
3 414 GRANT ST PITTSBURGH PA 15219 2409 1
4 800 N FRENCH ST WILMINGTON DE 19801 3594 3
5 NA NA NA NA NA 0