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
This solution has the assumption that all *.csv
files have the same structure.
(Untested)
fileList <- list.files(
pattern="*.csv$",
recursive=TRUE,
full.name=TRUE,
)
completeCSV <- data.frame()
for(file in fileList) {
print(file) # for debug: print current file
if (nrow(completeCSV) == 0) {
completeCSV <- read.csv(file)
} else {
curDF <- read.csv(file) # could also be read.csv2()
rbind(completeCSV, curDF)
}
}
write.csv(completeCSV) # could also be write.csv2()