set.seed(123)
gm <- gapminder::gapminder
gm <- gm %>% mutate(comb = sample(c(NA, "a-b", "a-d", "b-c", "d-e"),size = nrow(gm),replace = TRUE))
gm_nest <- gm %>% tidyr::nest(country_data = -continent)
gm_nest %>%
nest_extract(.nest_data = country_data,
col = comb,
into = c("var1","var2"),
regex = "([[:alnum:]]+)-([[:alnum:]]+)")
Run the code above in your browser using DataLab