-1

I'm trying to calculate the driving distance between two coordinate locations. Here's my code:

library(tidyverse)
library(googleway)

distances %>%
  mutate(distance = google_distance(origins = origin, destinations = destination, key = 'API KEY'))

Here's my dataset - https://pastebin.com/d6Z6b2K5

I get this error:

Error in mutate():
! Problem while computing distance = google_distance(...).
✖ distance must be size 294 or 1, not 5.

I'd really appreciate some help with this!

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139

1 Answers1

1

Here's the solution that worked for me

mutate(distance = purrr::map2(origin, destination, ~ google_distance(.x, .y, key = 'API KEY')))
  • 3
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 04 '22 at 03:57