Append multiple csv files into one file using R

前端 未结 4 1412
[愿得一人]
[愿得一人] 2020-12-20 06:54

I Have multiple csv files that i have already read into R. Now I want to append all these into one file. I tried few things but getting different errors. Can anyone please h

4条回答
  •  悲哀的现实
    2020-12-20 07:44

    You can use a combination of lapply(), and do.call().

    ## cd to the csv directory
    setwd("mycsvs")
    
    ## read in csvs
    csvList <- lapply(list.files("./"), read.csv, stringsAsFactors = F)
    
    ## bind them all with do.call
    csv <- do.call(rbind, csvList)
    

    You can also use fread() function from the data.table package and rbindlist() instead for a performance boost.

提交回复
热议问题