Skip to content
Prev 165295 / 398506 Next

Globbing Files in R

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: