0

I'm trying to solve a problem using r

I have four columns in my dataframe, start_lat, end_lat, start_lng, end_lng and I want to create a new column called ride_distance measuring the difference between the 4 columns.

How do I go about this please ?

start_lat <- c(41.9, 42, 42, 41.9, 41.9)
start_lng <- c(-87.7, -87.7, -87.7, -87.8, -87.6)
end_lat <- c(42, 41.9, 42, 41.9, 41.9)
end_lng <- c(-87.7, -87.7, -87.7, -87.8, -87.6)


distance <- data.frame(start_lat, end_lat, start_lng, end_lng)

Created on 2022-10-15 with reprex v2.0.2

  • This question has been answered at least a few times on this forum. Does this help? https://stackoverflow.com/questions/32363998/function-to-calculate-geospatial-distance-between-two-points-lat-long-using-r – Jon Spring Oct 14 '22 at 19:41
  • Does this answer your question? [Function to calculate geospatial distance between two points (lat,long) using R](https://stackoverflow.com/questions/32363998/function-to-calculate-geospatial-distance-between-two-points-lat-long-using-r) – Matt Kocak Oct 14 '22 at 20:57

0 Answers0