Given a list of event locations:
event.coords <- data.frame(
event.id = letters[1:5],
lats = c(43.155, 37.804, 26.71, 35.466, 40.783),
lons = c(-77.616,-122.271, -80.064, -97.513, -73.966))
and the centroids of locales (which happen to be ZIP codes, but could be states, countries, etc.):
locale.centroids <-
data.frame(
locale.id = 1:5,
lats = c(33.449, 41.482, 40.778, 43.59, 41.736),
lons = c(-112.074, -81.67, -111.888, -70.335, -111.834))
I would like to calculate how far each locale centroid is from the nearest event. My data contains 100,000 locales, so I need something computationally efficient.