[R] read.table from a list of filenames

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 29 00:06:14 CET 2004


thomas hills <thills at mail.utexas.edu> writes:

> I am wondering if it is possible to read.table repeatedly from a list 
> of file names into a new list of table names.
> 
> For example:
> 
> filenames <- list.files()
> 
> then with a function like
> 
> rf <- function(i) {
> word??(filename[i]) <- read.table(filenames[i]) }
> 
> I can't seem to find a function like word?? that will be the object of 
> another operation.   If this worked, then I could repeat it for the 
> length of filenames.
> 
> Also, even the following function seems to give me an error, but I 
> don't yet know why.
> 
> rf <- function(nam, i) {  nam <- read.table(filenames[i]) }
> 
> 
> Any help would be very much appreciated.

Something like

listoftables <- lapply(filenames, read.table)
names(listoftables) <- filenames

might be what you are looking for.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list