Is there a way to unnest list columns in R to remove hierarchy and retain the individuals components in a vector? I tried unnest function from tidyr but I get an error
library(dplyr)
library(tidyr)
mydf <- tibble(
a1 = c(20, 21, 23, 45),
a2 = list(c("Male", "Female"), c("Yes", "No"),
c("Secondary", "Primary", "Tertiary"),
c("13-14", "15-16", "17 - 18"))
)
#---- Desired output
mydf1 <- tibble(
a1 = c(20, 21, 23, 45),
a2 = c("Male, Female", "Yes, No",
"Secondary, Primary, Tertiary",
"13-14, 15-16, 17 - 18"))
#--- Trial
mydf %>%
mutate(a3 = unnest(a2))