Quantcast

Batch importing data

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Batch importing data

Kexin Yu
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Batch importing data

Michael Weylandt
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.

Michael

On Fri, Apr 27, 2012 at 11:23 AM, jiangxijixzy <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Batch importing data

David Winsemius

On Apr 27, 2012, at 1:30 PM, R. Michael Weylandt wrote:

> 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.

And if you wanted to have them named, then something like:

inputfils <- lapply(list.files(patt=".txt"), read.table)
names(inputfils)  <- sub("\\.txt", "", list.files(patt=.txt) )

Then this will let you access a particular file by name:

inputfils[["Oil_20030801"]]

--  
David.

>
> Michael
>
> On Fri, Apr 27, 2012 at 11:23 AM, jiangxijixzy  
> <[hidden email]> 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.
>>
>> ______________________________________________
>> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Batch importing data

Kexin Yu
This post has NOT been accepted by the mailing list yet.
In reply to this post by Michael Weylandt
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Batch importing data

Kexin Yu
In reply to this post by David Winsemius
CONTENTS DELETED
The author has deleted this message.
Loading...