zipcodeR
When a ZIP Code Is the Only Location in the Data
A health researcher may know a patient’s ZIP code and the ZIP code of a clinic. I built zipcodeR so researchers could use those two fields to estimate the distance between their geographic centers. That gives a measure of proximity even when street addresses are unavailable.
I brought the lookups, distance calculations and Census geographic identifiers into one R package. An analyst can use the same script to group records by county, identify nearby ZIP codes or prepare data for a map.
- 124K+
- Total CRAN downloads, as of October 2026
- 53+
- Peer-reviewed citations, as of March 2026
- ~1,627
- Downloads in an average month
Keeping Published Analyses Reproducible
Updating geographic data can change a study’s results even when its code stays the same. I kept the original functions tied to their historical data. For new analyses, researchers can select a named data release, record that version alongside their code and use it again when they repeat the study.
Research Impact
In a study of telemedicine appointments, researchers used zipcodeR to look up population density, land area and median income for patients’ ZIP codes. Those measures helped them compare the communities served by in-person and remote visits.
- 2025
Multiethnic Skin Cancer Risk Model Nature Communications
- 2025
NCI Clinical Trial Demographics Cancer Discovery
- 2024
Congenital Heart Disease Care Gaps J Am Heart Assoc
- 2023
COVID-19 Behavioral Response European Economic Review
- 2025
Glaucoma Surgery Access Ophthalmology
- 2025
Prematurity & Pediatric Asthma Communications Medicine
- 2025
- 2026
Local Personalization for Charitable Crowdfunding MIS Quarterly
View all 53+ citations on Google Scholar
Installation
# Install from CRAN
install.packages("zipcodeR")
# Or install development version from GitHub
# install.packages("remotes")
remotes::install_github("gavinrozzi/zipcodeR") Key Features
-
Distance Calculations
Compute geodesic distances between ZIP codes using the Haversine formula. The result estimates straight-line proximity between ZIP code centers.
-
Demographic Data
Access population, income, housing, and other census statistics by ZIP code. Used for market research and demographic analysis.
-
Geographic Boundaries
Join ZIP-level values to Census ZIP Code Tabulation Area boundaries to map patterns across communities.
-
ZIP Code Lookups
Search ZIP codes by city, county, state, or coordinates. Reverse geocode lat/lon to ZIP codes instantly.
Example Usage
library(zipcodeR)
# Look up information for a ZIP code
zip_info <- reverse_zipcode("08901")
# Calculate distance between two ZIP codes
distance <- zip_distance("08901", "10001")
# Get all ZIP codes in a state
nj_zips <- search_state("NJ")
# Find ZIP codes within radius
nearby <- search_radius(40.49, -74.45, radius = 25)
# Pin the reference data for a new study
bundle <- download_zip_data_bundle("2026.09")
zip_distance_ng(bundle, "08731", "08901") Frequently Asked Questions
What is zipcodeR?
zipcodeR is an R package created by Gavin Rozzi for working with U.S. ZIP code data. It provides functions for distance calculations, demographic lookups, geographic boundaries, and more. The package is available on CRAN with 124,000+ total downloads and has 53+ peer-reviewed citations (as of March 2026).
How do I install zipcodeR in R?
Install zipcodeR from CRAN with: install.packages('zipcodeR'). For the development version, use: remotes::install_github('gavinrozzi/zipcodeR'). zipcodeR requires R >= 3.5.0 and works on Windows, macOS, and Linux.
How do I calculate the distance between two ZIP codes in R?
Use the zip_distance() function: library(zipcodeR); zip_distance('08901', '10001'). The function returns the great-circle distance between the centroids of the two ZIP codes in miles by default. zip_distance() handles missing or invalid ZIP codes gracefully and works with vectors of ZIP codes for batch calculations.
How do I find all ZIP codes within a radius of a given ZIP code in R?
Use search_radius(): library(zipcodeR); search_radius(40.49, -74.45, radius = 25). This returns every ZIP code whose centroid lies within 25 miles of those coordinates, plus its distance. Combine with merge() or dplyr::inner_join() to filter your dataset to observations within proximity of a target ZIP.
How do I assign ZIP codes to geographic regions (state, county, MSA) in R?
Use reverse_zipcode() to enrich a ZIP with state, county, FIPS code, and metro statistical area: zip_info <- reverse_zipcode(your_zips). The returned data frame has every administrative geography you need to group, weight, or aggregate ZIP-level observations. For custom regions, join your zip-to-region crosswalk against zip_info using zipcode as the key.
How do I geocode an address to a ZIP code in R?
zipcodeR is designed for ZIP-level analysis, not raw address geocoding. For full address-to-coordinate geocoding use a dedicated geocoder (e.g., the tidygeocoder package, the U.S. Census geocoder, or for New Jersey addresses specifically, Gavin Rozzi's njgeo package which uses the official NJ state geocoding API). Once you have coordinates, use geo_zipcode(lat, lng) in zipcodeR to get the ZIP code for those coordinates.
How do I get Census demographic data (population, income, race) by ZIP code in R?
Use zip_code_db, the data frame embedded in zipcodeR that contains demographic and geographic information for every U.S. ZIP code. For more recent or specialized variables, combine zipcodeR with tidycensus to pull current ACS estimates at the ZCTA level. Example: library(zipcodeR); my_zips <- search_state('NJ'); pop_data <- merge(my_zips, zip_code_db[c('zipcode','population','median_household_income')], by = 'zipcode').
How do I plot ZIP codes on a map in R?
Combine zipcodeR with sf and tigris (or rnaturalearth) for the boundary geometries: library(zipcodeR); library(tigris); zcta <- zctas(state = 'NJ'); zcta_data <- merge(zcta, zip_code_db, by.x = 'ZCTA5CE20', by.y = 'zipcode'). Then plot with ggplot2 + geom_sf(aes(fill = population), data = zcta_data). For interactive maps, swap ggplot2 for leaflet.
What can zipcodeR do?
zipcodeR provides functions to: calculate distances between ZIP codes, look up demographic and Census data by ZIP code, prepare ZIP-level data for mapping, reverse geocode coordinates to ZIP codes, search for ZIP codes by city/county/state, and find ZIP codes within a radius. It ships with an embedded SQLite database so lookups are fast and offline.
Who created zipcodeR?
zipcodeR was created by Gavin Rozzi, a civic technologist and data scientist based in New Jersey. The package was first published on CRAN in September 2020 and is actively maintained with regular updates. It is published under the GPL-3 license and is free for academic, commercial, and personal use.
What research has cited zipcodeR?
zipcodeR has 53+ peer-reviewed citations (as of March 2026) in journals including Nature Communications, Cancer Discovery, MIS Quarterly, the Journal of the American Heart Association, and JAMIA Open. Research spans cancer risk modeling, clinical trials, cardiovascular care, environmental health, behavioral economics, telemedicine, and healthcare access. The research section links to individual studies and the citation index.
Publications
- 2021
Related Articles
- Apr 27, 2026
- Apr 26, 2026
- Apr 25, 2026
- Mar 21, 2026