# single year
index_distance(
m = subset(korea_reg, year == 2020),
d = korea_dist
)
library(dplyr)
library(tidyr)
library(purrr)
# multiple years
korea_reg %>%
nest(m = c(orig, dest, flow)) %>%
mutate(d = list(korea_dist)) %>%
mutate(i = map2(.x = m, .y = d,
.f = ~index_distance(m = .x, d = .y, long = FALSE))) %>%
select(-m, -d) %>%
unnest(i)
Run the code above in your browser using DataLab