0

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.

  1. Pipe the data to mutate and create a new column called distance.
  2. Use the pmap function with list inside to assign the row's starting and ending points to a,b,x,y
  3. 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
  • I think you might just need a tilde in front of your call to `distRhumb` because you're trying to use a formula notation? So `~ distRhumb( c(..1, ..2), c(..3, ..4)) ))` – Captain Hat Jun 08 '22 at 14:04
  • Thank you for the response. I ended up figuring it out using a different method, but I am going to go try this too! – GatorAdmiral03 Jun 18 '22 at 06:09

0 Answers0