Trying to merge multiple csv files in R -
i'm attempting merge multiple csv files using r. of csv files have same fields , shared folder containing these csv files. i've attempted using following code:
multmerge=function(mypath) { filenames=list.files(path=mypath, full.names=true) datalist= lapply(filenames, function (x) read.csv(file=x, header=true)) reduce(function(x,y) merge(x,y), datalist)}
i entering path "y:/r practice/specdata". ouput when apply function 300 or csv files, result gives me columns names, beneath has <0 rows> (or 0-length row.names). please let me know if have suggestions on why isn't working , how can fix it.
for shorter, faster solution
library(dplyr) library(readr) df <- list.files(full.names = true) %>% lapply(read_csv) %>% bind_rows
Comments
Post a Comment