I'm doing an analysis where I want to see which of the hospitals in my dataset is closet to the nearest nursing home. So for each nursing home I my goal is to find the hospital within the shortest distance.
I have used st_distance to calculate this but I would like to see the actual names of the Origin and Destination and not just the calculated distance.
### Calculating the distance between Nursing Homes and Hospitals ###
#distance from nursing home TO hospitals
distances <- st_distance(nursing_health, hospitals) * 0.000621371
#converting meters to miles
#finding the distance to the closest hospital for each RHF
nursing_health <- nursing_health %>%
mutate(distance_to_hospital = as.vector(apply(distances, 1, min)))
Is there a way I can actually see the names of which hospitals have the closest distance to a given nursing home?