Reputation: 171
I have a list of length 42 containing tibbles that I would like to join into a single tibble.
the way I would do it is:
full_join(list[[1]],list[[2]],list[[3]]...list[[42]])
I'm sure there's an easier way to do it, but I could not figure it out. can someone help?
Upvotes: 1
Views: 730
Reputation: 1275
Another way to combine lists of tibbles is with list_rbind
(from purrr
), and this also allows you to add in an id if you want to keep track of which list element everything came from (rather than just joined them all together and losing this information.)
list_rbind(list, names_to='element_number')
I have used this technique when reading in PDFs using pdftools::pdf_data
(which returns a list of tibbles). So that I can keep the page numbers as well and just return one large tibble, I use:
pdftools::pdf_data(fname) |>
list_rbind(names_to='pagenum')
Upvotes: 0
Reputation: 2452
In tidyverse, you could use
purrr::reduce(df_list, dplyr::full_join)
Upvotes: 1