I have coordinates for hundreds of cities. From climate model data I want to find the closest coordinates to my cities. I can do this individually for each city using the code below, but there must be an easier way to do this for all cities rather than listing each one out like below?
# Resolution of climate model data
OBS.lat = seq(-90, 90, 0.5)
OBS.lon = seq(-180, 180, 0.5)
# Set coordinates for cities
BERLlat = 52.52
BERLlon = 13.39
BERNlat = 46.95
BERNlon = 7.45
BUElat = -34.60
BUElon = -58.38
BERL.lat=which.min(abs(OBS.lat-BERLlat))
BERL.lon=which.min(abs(OBS.lon-BERLlon))
BERN.lat=which.min(abs(OBS.lat-BERNlat))
BERN.lon=which.min(abs(OBS.lon-BERNlon))
BUE.lat=which.min(abs(OBS.lat-BUElat))
BUE.lon=which.min(abs(OBS.lon-BUElon))