How to merge csv files from nested folders in R

前端 未结 3 1297
陌清茗
陌清茗 2020-12-21 10:52

I have a large collection of csv files that are in different folders and in folders within folders that I need to merge into one file. It would be easy if they were all in o

3条回答
  •  既然无缘
    2020-12-21 11:25

    Here is a solution with dplyr

    # get list of files ending in csv in directory root
    dir(root, pattern='csv$', recursive = TRUE, full.names = TRUE) %>%
      # read files into data frames
      lapply(FUN = read.csv) %>%
      # bind all data frames into a single data frame
      rbind_all %>%
      # write into a single csv file
      write.csv("all.csv")
    

提交回复
热议问题