Skip to content
Prev 165345 / 398506 Next

Globbing Files in R

Gundala Viswanath wrote:

            
Something like this has been suggested in R-help before:

files <- dir()
results <- lapply(files, yourprocessing())

The dir function has path and pattern arguments to select the set of 
files you want.

This works fine when there are no problems, but often I'll use a for 
loop so problem files can be dealt with differently when necessary.

Perhaps something like this:

ProcessList <- dir(pattern="InPerson*")

for (i in 1:length(ProcessList))
{
   filename <- ProcessList[i]
   . . .
}


efg

Earl F Glynn
Overland Park, KS