zipcodeR
The R package powering peer-reviewed research worldwide
About zipcodeR
zipcodeR is an R package enabling breakthrough research across public health, epidemiology, economics, and environmental science. Created by Gavin Rozzi and published on CRAN, the package has been cited in Nature, Cancer Discovery, and other leading peer-reviewed journals.
Whether you're calculating distances between ZIP codes, looking up demographic information, performing spatial joins, or building maps, zipcodeR provides a clean, intuitive interface that handles the complexity of ZIP code data for you.
The package includes an embedded SQLite database with comprehensive ZIP code data, ensuring fast lookups without external API dependencies. It's well-documented, actively maintained, and follows modern R development best practices.
Research Impact
With 53 peer-reviewed citations and growing, zipcodeR has become essential infrastructure for spatial research across medicine, public health, economics, and environmental science.
Multiethnic Skin Cancer Risk Model
Machine learning model addressing health disparities in skin cancer detection across ethnic groups.
2025 Cancer DiscoveryNCI Clinical Trial Demographics
Analysis of demographic representation in early-phase cancer research trials from 2000-2023.
2025 J Am Heart AssocCongenital Heart Disease Care Gaps
Social determinants of health and child opportunity index implications for pediatric cardiac care.
2024 European Economic ReviewCOVID-19 Behavioral Response
How political ideology influenced pandemic-related behaviors and prosocial responses.
2023 Environmental ResearchAir Pollution & Cognitive Decline
Ultrafine particle exposure and aging-related cognitive impairment in older Americans.
2023 OphthalmologyGlaucoma Surgery Access
Geographic distribution analysis of surgical access using the IRIS Registry.
2025 Communications MedicinePrematurity & Pediatric Asthma
Environmental pollution and genetic susceptibility impact on premature infant outcomes.
2025 M&SOMOutpatient Clinic Visit Incompletion
Empirical study of waiting dynamics in online vs. in-person healthcare settings.
2025 MIS QuarterlyLocal Personalization for Charitable Crowdfunding
Field experiment on geographic personalization in crowdfunding using ZIP code-level targeting.
2026View 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. Perfect for delivery routing, service area analysis, and proximity searches.
Demographic Data
Access population, income, housing, and other census statistics by ZIP code. Great for market research and demographic analysis.
Geographic Boundaries
Retrieve ZIP code boundary polygons for mapping and spatial analysis. Works seamlessly with sf and leaflet packages.
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("08901", radius = 25) 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 116,000+ total downloads and is cited in 53+ peer-reviewed publications.
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('08901', radius = 25). This returns every ZIP code whose centroid lies within 25 miles of the input ZIP, 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, retrieve ZIP code boundaries 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 March 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 in journals including Nature, Cancer Discovery, MIS Quarterly, Communications Medicine, Journal of the American Heart Association, European Economic Review, and Ophthalmology. Research spans cancer risk modeling, clinical trials, cardiovascular care, environmental health, behavioral economics, telemedicine, and healthcare access. The full citation list is in the zipcodeR Software Impacts paper.
Publications
Related Articles
How to plot ZIP codes on a map in R with zipcodeR
Build choropleth and dot maps of US ZIP codes in R using zipcodeR for the data layer and tigris + sf + ggplot2 for the geometry. Includes interactive maps with leaflet.
Apr 27, 2026How to assign ZIP codes to geographic regions in R
Roll up ZIP-level data to county, state, MSA, or any custom region in R using zipcodeR. Covers reverse_zipcode() for built-in geographies and crosswalk joins for custom regions.
Apr 26, 2026How to calculate distance between ZIP codes in R
A practical guide to calculating great-circle distance between ZIP codes in R using zipcodeR — including pairwise lookups, batch calculations, and finding all ZIPs within a radius.
Apr 25, 2026zipcodeR Reaches 53+ Peer-Reviewed Citations, Including MIS Quarterly
My open-source R package for ZIP code analysis has now been cited in 53+ peer-reviewed publications, including MIS Quarterly—a Financial Times Top 50 journal.
Mar 21, 2026