2

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?

Chris
  • 251
  • 1
  • 7
  • You should have used https://stackoverflow.com/q/11433432/680068 , so that your dataframes are in a list, then `all <- bind_rows(myListOfDataFrames)` – zx8754 Mar 10 '21 at 21:33

1 Answers1

0

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')
akrun
  • 874,273
  • 37
  • 540
  • 662