How to import multiple data files (the fast way)

February 6, 2017

(This article was first published on R – Inside data, and kindly contributed to R-bloggers)


Sometimes you have your data stored in multiple csv files and want to load them into a single data frame in R. There are several answers on the web to this questions and I recently found a fast solution to this problem.

# packages

# set wd

# import files
files = list.files(pattern="*.csv")
dataset =, lapply(files, fread))

# transform data to df
dataset <-

The code above uses both lapply and the cool fread function from the data.table package to load in your data in a quiet fast manner. I recommend to try out this approach if you dealing with long import times.

Make sure you check out my Github for other data driven projects.

To leave a comment for the author, please follow the link and comment on their blog: R – Inside data. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)