[R] batch process file in R

Romain Francois romain.francois at dbmail.com
Thu Mar 12 14:35:30 CET 2009


tedzzx wrote:
> Dear R experts,
>
> I have a folder names "200209" and in this folder there are many data files,
> such as: 
> "BA020902.txt","BA020903.txt","BA020904.txt",
> "BA020905.txt","BA020906.txt","BA020909.txt",
> "BA020910.txt","BA020911.txt","BA020912.txt",
> "BA020913.txt","BA020916.txt","BA020917.txt",
> "BA020918.txt","BA020919.txt","BA020920.txt",
> "BA020923.txt","BA020924.txt","BA020925.txt",
> "BA020926.txt","BA020927.txt","BA020930.txt",
> "GMAS0209.txt","MAST0209.txt"
>
> I want to imort all these data files into R at once without typing tedious 
> a<-read.table("BA020902.txt"),
> b<-read.table("BA020903.txt").....
>
> Thanks
>
> Ted
>   
How about something like that:

out <- sapply( dir( pattern = "\\.txt$" ), read.table )

Romain

-- 
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr




More information about the R-help mailing list