Skip to content
Prev 163896 / 398506 Next

Running R Script on a Sequence of Files

Use dir to get the names and then lapply over them with a
custom anonymous function where L is a list of the returned
values:

# assumes file names are those in
# current directory that end in .dat
filenames <- dir(pattern = "\\.dat$")

L <- lapply(filenames, function(x) {
  DF <- read.table(x, ...whatever...)
  somefunction(DF)
})

Now L is a list of the returned 900 values.  Alternately you could use
a loop.
On Fri, Dec 5, 2008 at 1:01 PM, Chris Poliquin <poliquin at sas.upenn.edu> wrote: