I have a folder containing 332 csv files. The name of the files are as follows 001.csv, 002.csv, 003.csv, ............ , 330.csv, 331.csv , 332.csv . All the files have same number of variables and same format.
I need to read all the files in one dataframe. I have been reading each one and then using rbind, but this is too cumbersome.
Need help.
Try lapply and do.call
file_names <- dir() #where you have your files your_data_frame <- do.call(rbind,lapply(file_names,read.csv))
Solution with data.table
, answer is taken from another post in SO which I used sometimes back.
library(data.table) files <- list.files(path = "/etc/dump",pattern = ".csv") temp <- lapply(files, fread, sep=",") data <- rbindlist( temp )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With