Merge many lists into one using a pattern

34 views Asked by At

I have many data files that I want to merge. They are names with a certain pattern. I managed to import them into the Global Environment, so there are now many lists waiting to be merged into one. Is there a way to do this using a pattern? Here is what I did until now:

    files <- list.files(pattern = "summary_.*RData") # any file in the directory that starts with 'summary_'
    for (i in files) {
      load(i)
    }

    names_of_lists <- list.files(pattern = "*_bigmarkets") # any object in Global Environment that contains (*)

So I get a character vector with the names of all the lists I try to merge, and here I am stuck.

1

There are 1 answers

1
goblinshark On

Not sure exactly what output you want but you could try something like

mylists <- list()
for(name in names_of_lists){
mylists <- append(mylists, get(name))
}

rbindlist(mylists)