[R] Batch importing data

R. Michael Weylandt michael.weylandt at gmail.com
Fri Apr 27 19:30:32 CEST 2012

list.files() will give you all the file names in your working
directory (you can also give it a pattern argument) then can loop over
those with something like:

lapply(list.files(), read.table)

which will put all your files in a list object. This is generally
considered much more convenient than trying to create a whole bunch of
objects with different names programmatically.


On Fri, Apr 27, 2012 at 11:23 AM, jiangxijixzy <jiangxijixzy at 163.com> wrote:
> I want to import data from about 2000 text files, and hope to create a data
> frame to make it easy to quote the data.
> For example, the files like this
> Oil_20030801.txt, Oil_20030804.txt, Oil_20030805.txt … Oil_20120427.txt
> The dates aren’t continuous. I want to create the data frame called “Oil”,
> like that
> Oil20030801<-read.table(“E:/Oil/ Oil_20030801.txt”)
> Oil20030804<-read.table(“E:/Oil/ Oil_20030804.txt”)
> Oil20030805<-read.table(“E:/Oil/ Oil_20030805.txt”)
>> Oil20120427<-read.table(“E:/Oil/ Oil_20120427.txt”)
> It is a time consuming way. How can I perform a convenient way? Thank you!
> --
> View this message in context: http://r.789695.n4.nabble.com/Batch-importing-data-tp4592997p4592997.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list