I have two separate data tables that I want to find the closet zip code from one data table to the other. From the SiteZip table, I want the zip codes to loop through the ConsumerZip table to obtain the shortest distance between zip codes. I used the zipcodeR package to assign lat and long to it. The two tables are below. The first table are the locations of stores. The other table are customer locations. I want to be able to create a single table that shows the closest store for each customer. I have researched for a couple days and haven't found many requests that match what I'm looking for. Ultimately I would map the store locations with a density circle by customer location. Thank you in advance for any help you can provide.
head(StoreZip)
Zip Store Address1 City State lat lng
1: 01026 11111 151 South Street Cummington MA 42.48 -72.93
2: 01040 11112 303 Beech St. Holyoke MA 42.22 -72.64
3: 01104 11113 417 Liberty St. Springfield MA 42.13 -72.57
4: 01104 11114 2155 Main St. Springfield MA 42.13 -72.57
5: 01301 11115 55 Federal St. Greenfield MA 42.63 -72.59
6: 01301 11116 1 Arch Place Greenfield MA 42.63 -72.59```
```head(CustomersZip)
Zip ID Address1 City State lat lng
1: 01001 65484654805 1548 MAIN STREET AGAWAM MA 42.07 -72.63
2: 01001 64846124846 569 MAPLE ST AGAWAM MA 42.07 -72.63
3: 01001 68421548945 68 PLANTATION DR AGAWAM MA 42.07 -72.63
4: 01001 84051545484 154 South DR AGAWAM MA 42.07 -72.63
5: 01001 97545154848 985 Main St AGAWAM MA 42.07 -72.63
6: 01002 64841515484 54 KING ST PELHAM MA 42.38 -72.52