Skip to content
Prev 173495 / 398503 Next

batch process file in R

If these are the only files in the directory, then you might try...
(File paths will need to change if the folder "200209" isn't in the
working directory)

fpath <- "./200209"
a <- list.files(fpath)
for(i in 1:length(a)){
     assign(paste("y",i,sep=""),read.table(paste(fpath,a[i],sep="/")))
}

Another option is to put them in a list...

for(i in 1:length(a)){
     y[[i]] <- read.table(paste(fpath,a[i],sep="/")
}

or with lapply...

y <- lapply(1:length(a), function(i) read.table(paste(fpath,a
[i],sep="/"))

Hope this helps.

Cheers,
Derek
On Mar 12, 7:52?am, tedzzx <zengzhenx... at gmail.com> wrote: