user18373817
user18373817

Reputation: 171

Join list large list into a single tibble

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

Answers (3)

bryn
bryn

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

langtang
langtang

Reputation: 24722

you can use Reduce.

Reduce(full_join, list)

Upvotes: 1

Andrea M
Andrea M

Reputation: 2452

In tidyverse, you could use

purrr::reduce(df_list, dplyr::full_join)

Upvotes: 1

Related Questions