Stating from the following tbl_list
tbl1 = tibble(a = c(1, 2), b = c(3, 4))
tbl2 = tibble(a = c(10, 20), b = c(30, 40))
tbl_list = list(tbl1, tbl2)
tbl_names = c("tbl1", "tbl2")
names(tbl_list) = tbl_names
My goal is
e_tbl_list = list(tibble(a = c(1, 2),
b = c(3, 4),
tbl_name = c("tbl1", "tbl1")),
tibble(a = c(10, 20),
b = c(30, 40),
tbl_name = c("tbl2", "tbl2"))
)
However , it doesn't work when using this code
a_tbl_list = tbl_names %>% map(~ tbl_list[[.]] %>% mutate(tbl_name = .))