Title: | Data & Functions for Working with US ZIP Codes |
Version: | 0.3.5 |
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. |
License: | GPL-3 |
URL: | https://github.com/gavinrozzi/zipcodeR/, https://www.gavinrozzi.com/project/zipcoder/ |
BugReports: | https://github.com/gavinrozzi/zipcodeR/issues/ |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.1 |
Imports: | rlang, stringr, raster, tidycensus, tidyr, dplyr, jsonlite, httr, curl, RSQLite, DBI |
Depends: | R (≥ 3.5.0) |
Suggests: | knitr, rmarkdown, markdown, readr, testthat (≥ 3.0.0), covr, tibble |
VignetteBuilder: | knitr, rmarkdown |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2022-10-03 03:33:35 UTC; gavinrozzi |
Author: | Gavin Rozzi |
Maintainer: | Gavin Rozzi <gr@gavinrozzi.com> |
Repository: | CRAN |
Date/Publication: | 2022-10-03 22:00:02 UTC |
Download updated data files needed for library functionality to the package's data directory. To be implemented for future updates.
Description
Download updated data files needed for library functionality to the package's data directory. To be implemented for future updates.
Usage
download_zip_data(force = FALSE)
Arguments
force |
Boolean, if set to TRUE will force overwrite existing data files with new version |
Value
Data files needed for package functionality, stored in data directory of package install
Examples
## Not run:
download_zip_data()
## End(Not run)
Returns that lat / lon pair of the centroid of a given ZIP code
Description
Returns that lat / lon pair of the centroid of a given ZIP code
Usage
geocode_zip(zip_code)
Arguments
zip_code |
A 5-digit U.S. ZIP code |
Value
tibble of lat lon coordinates
Examples
geocode_zip("07762")
geocode_zip("90210")
geocode_zip("90210")$lat
geocode_zip("90210")$lng
Get all congressional districts for a given ZIP code
Description
Get all congressional districts for a given ZIP code
Usage
get_cd(zip_code)
Arguments
zip_code |
A U.S. ZIP code |
Value
a named list of two-digit state code and two digit district code
Examples
get_cd("08731")
get_cd("90210")
Get all Census tracts within a given ZIP code
Description
Get all Census tracts within a given ZIP code
Usage
get_tracts(zip_code)
Arguments
zip_code |
A U.S. ZIP code |
Value
tibble of Census tracts and data from Census crosswalk file found for given ZIP code
Examples
get_tracts("08731")
get_tracts("90210")
Returns true if the given ZIP code is also a ZIP code tabulation area (ZCTA)
Description
Returns true if the given ZIP code is also a ZIP code tabulation area (ZCTA)
Usage
is_zcta(zip_code)
Arguments
zip_code |
A 5-digit U.S. ZIP code |
Value
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
Examples
is_zcta("90210")
is_zcta("99999")
is_zcta("07762")
Normalize ZIP codes
Description
Normalize ZIP codes
Usage
normalize_zip(zipcode)
Arguments
zipcode |
messy ZIP code to be normalized |
Value
Normalized zipcode
Examples
normalize_zip(0008731)
Given a ZIP code, returns columns of metadata about that ZIP code
Description
Given a ZIP code, returns columns of metadata about that ZIP code
Usage
reverse_zipcode(zip_code)
Arguments
zip_code |
A 5-digit U.S. ZIP code or chracter vector with multiple ZIP codes |
Value
A tibble containing data for the ZIP code(s)
Examples
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
Description
Get all ZIP codes that fall within a given congressional district
Usage
search_cd(state_fips_code, congressional_district)
Arguments
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 |
Value
tibble of all congressional districts found for given ZIP code, including state code
Examples
search_cd("34", "03")
search_cd("36", "05")
Search ZIP codes for a given city within a state
Description
Search ZIP codes for a given city within a state
Usage
search_city(city_name, state_abb)
Arguments
city_name |
Name of major city to search |
state_abb |
Two-digit code for a U.S. state |
Value
tibble of all ZIP code data found for given city
Examples
search_city("Spring Lake", "NJ")
search_city("Chappaqua", "NY")
Search ZIP codes for a county
Description
Search ZIP codes for a county
Usage
search_county(county_name, state_abb, ...)
Arguments
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. |
Value
tibble of all ZIP codes for given county name
Examples
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
Description
Returns all ZIP codes found within a given FIPS code
Usage
search_fips(state_fips, county_fips)
Arguments
state_fips |
A U.S. FIPS code |
county_fips |
A 1-3 digit county FIPS code (optional) |
Value
tibble of Census tracts and data from Census crosswalk file found for given ZIP code
Examples
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
Description
Search for ZIP codes that are within a given radius from a point
Usage
search_radius(lat, lng, radius = 1)
Arguments
lat |
latitude |
lng |
longitude |
radius |
distance to search in miles, set by default to 1 |
Value
a tibble containing the ZIP code(s) within the provided radius and distance from the provided coordinates in miles
Examples
## Not run:
search_radius(39.9, -74.3, 10)
## End(Not run)
Search for ZIP codes located within a given state
Description
Search for ZIP codes located within a given state
Usage
search_state(state_abb)
Arguments
state_abb |
Two-digit code representing a U.S. state |
Value
tibble of all ZIP codes for each state code defined in state_abb
Examples
search_state("NJ")
search_state(c("NJ", "NY", "CT"))
Search all ZIP codes located within a given timezone
Description
Search all ZIP codes located within a given timezone
Usage
search_tz(tz)
Arguments
tz |
Timezone |
Value
tibble of all ZIP codes found for given timezone
Examples
eastern <- search_tz("Eastern")
pacific <- search_tz("Mountain")
ZCTA to Census Tract (2010) Crosswalk
Description
A dataset containing the relationships between ZIP code tabulation areas (ZCTA) and Census Tracts. This contains selected variables from the official crosswalk file.
Usage
zcta_crosswalk
Format
A data frame with 148897 rows and 4 variables:
- ZCTA5
2010 ZIP Code Tabulation Area
- TRACT
2010 Census Tract Code
- GEOID
Concatenation of 2010 State, County, and Tract
Source
https://www.census.gov/geographies/reference-files/time-series/geo/relationship-files.html
ZIP Code Database
Description
A dataset containing detailed information for U.S. ZIP codes
Usage
zip_code_db
Format
A data frame with 41877 rows and 24 variables:
- zipcode
5 digit U.S. ZIP code
- zipcode_type
2010 State FIPS Code
- major_city
Major city serving the ZIP code
- post_office_city
City of post office serving the ZIP code
- common_city_list
List of common cities represented by the ZIP code
- county
Name of county containing the ZIP code
- state
Two-digit state code for ZIP code location
- lat
Latitude of the centroid for the ZIP code
- lng
Longitude of the centroid for the ZIP code
- timezone
Timezone of the ZIP code
- radius_in_miles
Radius of the ZIP code in miles
- area_code_list
List of area codes for telephone numbers within this ZIP code
- population
Total population of the ZIP code
- population_density
Population density of the ZIP code (persons per square mile)
- land_area_in_sqmi
Area of the land contained within the ZIP code in square miles
- water_area_in_sqmi
Area of the waters contained within the ZIP code in square miles
- housing_units
Number of housing units within the ZIP code
- occupied_housing_units
Number of housing units within the ZIP code
- median_home_value
Median home price within the ZIP code
- median_household_income
Median household income within the ZIP code
- bounds_west
Bounding box coordinates
- bounds_east
Bounding box coordinates
- bounds_north
Bounding box coordinates
- bounds_south
Bounding box coordinates
Source
https://github.com/MacHu-GWU/uszipcode-project/files/5183256/simple_db.log
Calculate the distance between two ZIP codes in miles
Description
Calculate the distance between two ZIP codes in miles
Usage
zip_distance(zipcode_a, zipcode_b, lonlat = TRUE, units = "miles")
Arguments
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. |
Value
a data.frame containing a column for each ZIP code and a new column containing the distance between the two columns of ZIP code
Examples
zip_distance("08731", "08901")
ZIP Code to Congressional District Relationship File
Description
A dataset containing mappings between ZIP codes and congressional districts
Usage
zip_to_cd
Format
A data frame with 45914 rows and 2 variables:
- ZIP
5 digit U.S. ZIP code
- CD
Four digit congressional district code (State FIPS code + district number)