I have a dataframe with the following columns in it already:
start_lat, start_long, end_lat, end_long.
I need to find the distance between the start/end points in each row. So far, this is what I got:
library(stringr)
library(dplyr)
library(magrittr)
library(forcats)
library(lubridate)
library(tidyr)
library(tidyverse)
library("geosphere")
## Create a new column called ride_distance and determine the ride length!
df2021 %<>%
mutate(distance = pmap(list(a = start_lng,
b = start_lat,
x = end_lng,
y = start_lng),
distRhumb(c(..1, ..2), c(..3, ..4))))
I adapted this from a previous stack over flow post and it makes sense in theory.
- Pipe the data to mutate and create a new column called distance.
- Use the pmap function with list inside to assign the row's starting and ending points to a,b,x,y
- Use distRhumb to find the distance between them.
However, r is throwing this error that I can't figure out:
Error in `mutate()`:
! Problem while computing `distance = pmap(...)`.
Caused by error in `.pointsToMatrix()`:
! ..1 used in an incorrect context, no ... to look in