{zipcodeR} has introduced several new functions geared towards geographic applications. In this vignette we will explore these new functions and some of their typical use cases with examples.

Calculating the distance between two ZIP codes

This version introduces the new function zip_distance() for calculating the distance between two ZIP codes in miles.

zip_distance('08731','08753')
##   zipcode_a zipcode_b distance
## 1     08731     08753     9.69

Geocoding a ZIP code

Users often are seeking to use zipcodeR to geocode ZIP codes. While it is possible to do this already, I have introduced a simple wrapper function that only returns that centroid coordinates of each provided ZIP code to make this process easier.

geocode_zip('08731')
## # A tibble: 1 × 3
##   zipcode   lat   lng
##   <chr>   <dbl> <dbl>
## 1 08731    39.9 -74.3

You can also pass a vector of ZIP codes to geocode to quickly geocode ZIP code-level data

geocode_zip(c('08731','08721','08753'))
## # A tibble: 3 × 3
##   zipcode   lat   lng
##   <chr>   <dbl> <dbl>
## 1 08721    39.9 -74.2
## 2 08731    39.9 -74.3
## 3 08753    40.0 -74.2

Searching for ZIP codes within a radius

Given a pair of latitude / longitude coordinates in WGS84 format you can search for all ZIP codes located within a provided radius in miles. This function will default to searching within 1 mile of your provided coordinates, but can be configured to search any arbitrary radius via the radius argument.

The below code searches for all ZIP codes within 20 miles of the

search_radius(39.9, -74.3, radius = 20)
## # A tibble: 41 × 2
##    zipcode distance
##    <chr>      <dbl>
##  1 08731       0   
##  2 08757       5.28
##  3 08721       5.31
##  4 08759       5.31
##  5 08722       5.70
##  6 08005       6.90
##  7 08758       7.22
##  8 08734       7.44
##  9 08741       7.72
## 10 08755       7.84
## # … with 31 more rows