Message-ID: <971536df0812210824m7a0ead40q2b82103d2a2877e7@mail.gmail.com>
Date: 2008-12-21T16:24:10Z
From: Gabor Grothendieck
Subject: Globbing Files in R
In-Reply-To: <73f827b50812210735w3956efe5l5cb0dfe35acc0e27@mail.gmail.com>
Try this:
file.names <- dir(pattern = glob2rx("/mydir/*.txt"))
for(fn in file.names) {
DF <- read.table(fn, ...)
...
}
Another possibility is:
file.names <- .. as above ...
out <- lapply(file.names, function(fn) {
DF <- read.table(fn, ...)
...
})
out will have one component per file formed from the result of the
each function application.
On Sun, Dec 21, 2008 at 10:35 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
> Dear all,
>
> For example I want to process set of files.
>
> Typically Perl's idiom would be:
>
> __BEGIN__
> @files = glob("/mydir/*.txt");
>
> foreach my $file (@files) {
> # process the file
> }
> __END__
>
> What's the R's way to do that?
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.
>