# single year
index_impact(
m = subset(korea_reg, year == 2020),
p = subset(korea_pop, year == 2020),
pop_col = "population"
)
# multiple years
library(dplyr)
library(tidyr)
library(purrr)
korea_reg %>%
nest(m = c(orig, dest, flow)) %>%
left_join(korea_pop) %>%
nest(p = c(region, population)) %>%
mutate(i = map2(.x = m, .y = p,
.f = ~index_impact(m = .x, p = .y, pop_col = "population", long = FALSE))) %>%
select(-m, -p) %>%
unnest(i)
Run the code above in your browser using DataLab