How to bind multiple dataframes in R

Viewed 172

I have imported many csv files into R using the code provided here: Read multiple CSV files into separate data frames

Now I have plenty of dataframes that I try to bind together into one. I've tried to use bind_rows to do that in a following way:

all<- bind_rows(names, .id = "id")

where "names" contains files/dataframes names.

I get the following error: "Argument 1 must have names."

How can I bind all the dfs?

1 Answers

If names store the object names of objects created in the global environment, then we need the value of those. We can get those with mget in a list

library(dplyr)
bind_rows(mget(names), .id = 'id')
Related