rdataframezipcodezipcoder

Get County and State using zip code (reverze_zipcode)


I have a list of unique client names and their zip codes.

I need to get extra information regarding the zip code such as state and county.

I discovered the package zipcodeR but wasn't able to use the reverse_zipcode function.

Below is a sample dataset.

df <- data.frame(name = c('Juan', 'Alice', 'Tim', 'Joe'),
                 zipc = c('11374', '11374', '11379', 'A145'))

I need an state and county column for my dataframe.

   name  zipc
1  Juan 11374
2 Alice 11374
3   Tim 11379
4   Joe  A145

Solution

  • Using zipcodeR package it can be done as follows:

    library(dplyr)
    library(zipcodeR)
    
    zip_code_db %>% 
      select(zipcode, state, county) %>% 
      right_join(df, by = c("zipcode"="zipc"), multiple = "all")
    
      zipcode state        county  name
    1   11374    NY Queens County  Juan
    2   11374    NY Queens County Alice
    3   11379    NY Queens County   Tim
    4    A145  <NA>          <NA>   Joe