I would like to calculate the distance between two latitude and longitude locations in a dataframe.
df <- tibble("lat1"=c(0,1,2),"lon1"=c(0,1,2),"lat2"=c(90,91,92),"lon2"=c(90,91,92))
df %>%
dplyr::mutate(distance_trip=mapply(FUN = distHaversine,c(lat1, lon1),c(lat2, lon2)))
The error that I am getting is:
*Error: Problem with `mutate()` column `distance_trip`.
ℹ `distance_trip = mapply(FUN = distHaversine, c(lat1, lon1), c(lat2, lon2))`.
x Wrong length for a vector, should be 2
Run `rlang::last_error()` to see where the error occurred.*
Not sure why I am unable to apply the function to the data frame.