Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. library(tidyverse)
  2. data1 <- tibble(city = c("Atlanta", "Tokyo", "Paris"),
  3. dist_Rome = c(1000, 2000, 300),
  4. dist_Miami = c(400, 3000, 1500),
  5. dist_Singapore = c(3000, 600, 2000),
  6. dist_Toronto = c(900, 3200, 1900))
  7.  
  8. library(tidyverse)
  9. data2 <- tibble(destination = c("Rome Italy", "Miami United States", "Singapore Singapore", "Toronto Canada"))
  10.  
  11. library(tidyverse)
  12. solution <- tibble(city = c("Atlanta", "Tokyo", "Paris"),
  13. dist_Rome = c(1000, 2000, 300),
  14. dist_Miami = c(400, 3000, 1500),
  15. dist_Singapore = c(3000, 600, 2000),
  16. dist_Toronto = c(900, 3200, 1900),
  17. nearest = c("Miami United States", "Singapore Singapore", "Rome Italy"))
  18.  
  19. library(tidyverse)
  20. solution <- data1 %>%
  21. mutate(nearest_hub = map(select(., contains("dist")), ~
  22. case_when(which.min(c(...)) ~ data2$destination),
  23. TRUE ~ "NA"))
  24. Error in which.min(c(...)) :
  25. (list) object cannot be coerced to type 'double'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement