Trying to merge multiple csv files in R

前端 未结 6 1105

I\'m attempting to merge multiple csv files using R. all of the CSV files have the same fields and are all a shared folder only containing these CSV files. I\'ve attempted

6条回答
  •  时光说笑
    2020-12-03 22:20

    Another option that has proved to work for my setup:

    multmerge = function(path){
      filenames=list.files(path=path, full.names=TRUE)
      rbindlist(lapply(filenames, fread))
    }
    
    
    path <- "Dropbox/rstudio-share/dataset/MB"
    DF <- multmerge(path)
    

    If you need a much granular control of your CSV file during the loading process you can change the fread by a function like so:

    multmerge = function(path){
      filenames=list.files(path=path, full.names=TRUE)
      rbindlist(lapply(filenames, function(x){read.csv(x, stringsAsFactors = F, sep=';')}))
    }
    

提交回复
热议问题