I have over 2000 *.rds files that are 18,000 obs and I would like to merge them all into one data.frame
. I know it's not efficient to grow objects with for
loops and have done so, but is taking really long as it progresses. Is there a faster way to do this?
Here are a couple of things I've tried so far:
lapply
:
mergedat <- do.call(rbind, lapply(list.files("dat/"), readRDS))
for
loop:
files <- list.files("dat/")
merged <- data.frame()
for (i in unique(files)){
df <- readRDS(paste0("dat/", i))
merged <- rbind(merged, df)
}