user13472708
user13472708

Reputation: 1

rbind all dataframes of a folder to one dataframe

How can I rbind all .RData dataframes which are stored in the same folder with identical column structure? I tried:

my_list <- list.files(my_path, full.names=TRUE)
my_files <- lapply(my_list, load, envir=.GlobalEnv)
library(dplyr)
df <- bind_rows(my_files, .id = "column_label")

Upvotes: 0

Views: 459

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389325

You can try :

lapply(my_files, load, .GlobalEnv)
df <- do.call(rbind, mget(sub('\\.RData', '', basename(my_files))))

Upvotes: 1

Related Questions