Title: | Data & Functions for Working with US ZIP Codes |
---|---|
Description: | Make working with ZIP codes in R painless with an integrated dataset of U.S. ZIP codes and functions for working with them. Search ZIP codes by multiple geographies, including state, county, city & across time zones. Also included are functions for relating ZIP codes to Census data, geocoding & distance calculations. |
Authors: | Gavin Rozzi [aut, cre] |
Maintainer: | Gavin Rozzi <[email protected]> |
License: | GPL-3 |
Version: | 0.3.5 |
Built: | 2025-03-12 04:15:28 UTC |
Source: | https://github.com/gavinrozzi/zipcoder |
Download updated data files needed for library functionality to the package's data directory. To be implemented for future updates.
download_zip_data(force = FALSE)
download_zip_data(force = FALSE)
force |
Boolean, if set to TRUE will force overwrite existing data files with new version |
Data files needed for package functionality, stored in data directory of package install
## Not run: download_zip_data() ## End(Not run)
## Not run: download_zip_data() ## End(Not run)
Returns that lat / lon pair of the centroid of a given ZIP code
geocode_zip(zip_code)
geocode_zip(zip_code)
zip_code |
A 5-digit U.S. ZIP code |
tibble of lat lon coordinates
geocode_zip("07762") geocode_zip("90210") geocode_zip("90210")$lat geocode_zip("90210")$lng
geocode_zip("07762") geocode_zip("90210") geocode_zip("90210")$lat geocode_zip("90210")$lng
Get all congressional districts for a given ZIP code
get_cd(zip_code)
get_cd(zip_code)
zip_code |
A U.S. ZIP code |
a named list of two-digit state code and two digit district code
get_cd("08731") get_cd("90210")
get_cd("08731") get_cd("90210")
Get all Census tracts within a given ZIP code
get_tracts(zip_code)
get_tracts(zip_code)
zip_code |
A U.S. ZIP code |
tibble of Census tracts and data from Census crosswalk file found for given ZIP code
get_tracts("08731") get_tracts("90210")
get_tracts("08731") get_tracts("90210")
Returns true if the given ZIP code is also a ZIP code tabulation area (ZCTA)
is_zcta(zip_code)
is_zcta(zip_code)
zip_code |
A 5-digit U.S. ZIP code |
Boolean TRUE or FALSE based upon whether provided ZIP code is a ZCTA by testing whether it exists in the U.S. Census crosswalk data
is_zcta("90210") is_zcta("99999") is_zcta("07762")
is_zcta("90210") is_zcta("99999") is_zcta("07762")
Normalize ZIP codes
normalize_zip(zipcode)
normalize_zip(zipcode)
zipcode |
messy ZIP code to be normalized |
Normalized zipcode
normalize_zip(0008731)
normalize_zip(0008731)
Given a ZIP code, returns columns of metadata about that ZIP code
reverse_zipcode(zip_code)
reverse_zipcode(zip_code)
zip_code |
A 5-digit U.S. ZIP code or chracter vector with multiple ZIP codes |
A tibble containing data for the ZIP code(s)
reverse_zipcode("90210") reverse_zipcode("08731") reverse_zipcode(c("08734", "08731")) reverse_zipcode("07762")$county reverse_zipcode("07762")$state
reverse_zipcode("90210") reverse_zipcode("08731") reverse_zipcode(c("08734", "08731")) reverse_zipcode("07762")$county reverse_zipcode("07762")$state
Get all ZIP codes that fall within a given congressional district
search_cd(state_fips_code, congressional_district)
search_cd(state_fips_code, congressional_district)
state_fips_code |
A two-digit U.S. FIPS code for a state |
congressional_district |
A two digit number specifying a congressional district in a given |
tibble of all congressional districts found for given ZIP code, including state code
search_cd("34", "03") search_cd("36", "05")
search_cd("34", "03") search_cd("36", "05")
Search ZIP codes for a given city within a state
search_city(city_name, state_abb)
search_city(city_name, state_abb)
city_name |
Name of major city to search |
state_abb |
Two-digit code for a U.S. state |
tibble of all ZIP code data found for given city
search_city("Spring Lake", "NJ") search_city("Chappaqua", "NY")
search_city("Spring Lake", "NJ") search_city("Chappaqua", "NY")
Search ZIP codes for a county
search_county(county_name, state_abb, ...)
search_county(county_name, state_abb, ...)
county_name |
Name of a county within a U.S. state |
state_abb |
Two-digit code for a U.S. state |
... |
if the parameter similar = TRUE, then send the parameter max.distance to the base function agrep. Default is 0.1. |
tibble of all ZIP codes for given county name
middlesex <- search_county("Middlesex", "NJ") alameda <- search_county("alameda", "CA") search_county("ST BERNARD", "LA", similar = TRUE)$zipcode
middlesex <- search_county("Middlesex", "NJ") alameda <- search_county("alameda", "CA") search_county("ST BERNARD", "LA", similar = TRUE)$zipcode
Returns all ZIP codes found within a given FIPS code
search_fips(state_fips, county_fips)
search_fips(state_fips, county_fips)
state_fips |
A U.S. FIPS code |
county_fips |
A 1-3 digit county FIPS code (optional) |
tibble of Census tracts and data from Census crosswalk file found for given ZIP code
search_fips("34") search_fips("34", "03") search_fips("34", "3") search_fips("36", "003")
search_fips("34") search_fips("34", "03") search_fips("34", "3") search_fips("36", "003")
Search for ZIP codes that are within a given radius from a point
search_radius(lat, lng, radius = 1)
search_radius(lat, lng, radius = 1)
lat |
latitude |
lng |
longitude |
radius |
distance to search in miles, set by default to 1 |
a tibble containing the ZIP code(s) within the provided radius and distance from the provided coordinates in miles
## Not run: search_radius(39.9, -74.3, 10) ## End(Not run)
## Not run: search_radius(39.9, -74.3, 10) ## End(Not run)
Search for ZIP codes located within a given state
search_state(state_abb)
search_state(state_abb)
state_abb |
Two-digit code representing a U.S. state |
tibble of all ZIP codes for each state code defined in state_abb
search_state("NJ") search_state(c("NJ", "NY", "CT"))
search_state("NJ") search_state(c("NJ", "NY", "CT"))
Search all ZIP codes located within a given timezone
search_tz(tz)
search_tz(tz)
tz |
Timezone |
tibble of all ZIP codes found for given timezone
eastern <- search_tz("Eastern") pacific <- search_tz("Mountain")
eastern <- search_tz("Eastern") pacific <- search_tz("Mountain")
A dataset containing the relationships between ZIP code tabulation areas (ZCTA) and Census Tracts. This contains selected variables from the official crosswalk file.
zcta_crosswalk
zcta_crosswalk
A data frame with 148897 rows and 4 variables:
2010 ZIP Code Tabulation Area
2010 Census Tract Code
Concatenation of 2010 State, County, and Tract
https://www.census.gov/geographies/reference-files/time-series/geo/relationship-files.html
A dataset containing detailed information for U.S. ZIP codes
zip_code_db
zip_code_db
A data frame with 41877 rows and 24 variables:
5 digit U.S. ZIP code
2010 State FIPS Code
Major city serving the ZIP code
City of post office serving the ZIP code
List of common cities represented by the ZIP code
Name of county containing the ZIP code
Two-digit state code for ZIP code location
Latitude of the centroid for the ZIP code
Longitude of the centroid for the ZIP code
Timezone of the ZIP code
Radius of the ZIP code in miles
List of area codes for telephone numbers within this ZIP code
Total population of the ZIP code
Population density of the ZIP code (persons per square mile)
Area of the land contained within the ZIP code in square miles
Area of the waters contained within the ZIP code in square miles
Number of housing units within the ZIP code
Number of housing units within the ZIP code
Median home price within the ZIP code
Median household income within the ZIP code
Bounding box coordinates
Bounding box coordinates
Bounding box coordinates
Bounding box coordinates
https://github.com/MacHu-GWU/uszipcode-project/files/5183256/simple_db.log
Calculate the distance between two ZIP codes in miles
zip_distance(zipcode_a, zipcode_b, lonlat = TRUE, units = "miles")
zip_distance(zipcode_a, zipcode_b, lonlat = TRUE, units = "miles")
zipcode_a |
First vector of ZIP codes |
zipcode_b |
Second vector of ZIP codes |
lonlat |
lonlat argument to pass to raster::pointDistance() to select method of distance calculation. Default is TRUE to calculate distance over a spherical projection. FALSE will calculate the distance in Euclidean (planar) space. |
units |
Specify which units to return distance calculations in. Choices include meters or miles. |
a data.frame containing a column for each ZIP code and a new column containing the distance between the two columns of ZIP code
zip_distance("08731", "08901")
zip_distance("08731", "08901")
A dataset containing mappings between ZIP codes and congressional districts
zip_to_cd
zip_to_cd
A data frame with 45914 rows and 2 variables:
5 digit U.S. ZIP code
Four digit congressional district code (State FIPS code + district number)
https://www.huduser.gov/portal/datasets/usps_crosswalk.html