[R] Reading and treating multiple files....

Mayeul KAUFFMANN mayeul.kauffmann at tiscali.fr
Tue Jul 27 23:10:58 CEST 2004


>I will get - in a few days-  a set of  separate files(one for each
records....~80'000 files pro year)
> named key.txt in which other info (measurements of pressure and velocity
at each second )
>is stocked; typically each one of this separate files will hold something
between 200 and
>1500 records....I'm supposed to do statistical analysis on this dataset,
on the yearly information
>Well, as you can suspect my problem is thus:
>- batch processing of these individual files :reading each file
(automatically!),

I suggest you put all files in a single directory, then you use
list.files ()  or dir()
to make a list of this files.
myfiles <- list.files ("c:\\mydir")  #on windows
Then you do a loop over these files with read.table()
You can create a column named "file" with the name of the file.

All of this can be done with:

data <- NULL;for (i in dir("c:\\temp")) data <-
rbind(data,cbind(file=i,read.table( paste("c:\\mydir\\",i,sep=""))))

Hope that helps

Mayeul KAUFFMANN
Univ. Pierre Mendes France
Grenoble - France




More information about the R-help mailing list