0

In R ,there data object/tibble names are 'data1,data2,data3,data4.....data100'(they are have same structure)

  1. how to combine all of them
  2. how to out put to csv files separately

Below code failed, anyone can help?

library(tidyverse)
library(data.table)
file <- ls(pattern = 'data') 
# rbind to a big dataframe
total_file <- rbindlist(file)

# write object to csv separately
for (i in c(1:100)){
  write.csv(paste0("data",i),paste0("data",i,".csv"))
}
anderwyang
  • 1,801
  • 4
  • 18
  • See the linked posts, one is for importing the other one is for exporting. You are doing both wrong. – zx8754 Jan 12 '23 at 09:36
  • in the linkage , the data ready to write out are in a list , in my question the object are stored separately in RAM , please help Thanks! – anderwyang Jan 12 '23 at 09:45
  • 1
    Then there is no need for *rbindlist*, try: `for(i in (ls(pattern = "data")){ write.csv( get(i), paste0(i, ".csv")) }`. I added more relevant 3rd link. – zx8754 Jan 12 '23 at 10:17
  • Thanks , the get() function can solver my question. – anderwyang Jan 17 '23 at 01:00

0 Answers0