Read and rbind multiple csv files

前端 未结 3 1732
心在旅途
心在旅途 2020-12-06 13:23

I have a series of csv files (one per anum) with the same column headers and different number of rows. Originally I was reading them in and merging them like so;

         


        
3条回答
  •  悲哀的现实
    2020-12-06 13:47

    Find files (list.files) and read the files in a loop (lapply), then call (do.call) row bind (rbind) to put all files together by rows.

    myMergedData <- 
      do.call(rbind,
              lapply(list.files(path = "N:/Ring data by cruise"), read.csv))
    

    Update: There is a vroom package, according to the manuals it is much faster than data.table::fread and base read.csv. The syntax looks neat, too:

    library(vroom)
    myMergedData <- vroom(files)
    

提交回复
热议问题