Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- data1 <- tibble(city = c("Atlanta", "Tokyo", "Paris"),
- dist_Rome = c(1000, 2000, 300),
- dist_Miami = c(400, 3000, 1500),
- dist_Singapore = c(3000, 600, 2000),
- dist_Toronto = c(900, 3200, 1900))
- library(tidyverse)
- data2 <- tibble(destination = c("Rome Italy", "Miami United States", "Singapore Singapore", "Toronto Canada"))
- library(tidyverse)
- solution <- tibble(city = c("Atlanta", "Tokyo", "Paris"),
- dist_Rome = c(1000, 2000, 300),
- dist_Miami = c(400, 3000, 1500),
- dist_Singapore = c(3000, 600, 2000),
- dist_Toronto = c(900, 3200, 1900),
- nearest = c("Miami United States", "Singapore Singapore", "Rome Italy"))
- library(tidyverse)
- solution <- data1 %>%
- mutate(nearest_hub = map(select(., contains("dist")), ~
- case_when(which.min(c(...)) ~ data2$destination),
- TRUE ~ "NA"))
- Error in which.min(c(...)) :
- (list) object cannot be coerced to type 'double'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement