[R] read.table from a list of filenames

Thomas Lumley tlumley at u.washington.edu
Wed Dec 29 00:05:38 CET 2004


On Tue, 28 Dec 2004, thomas hills wrote:

> 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]) }

lapply(filenames, read.table)

will do what I think you want to do.

[It is possible to assign each file to a variable whose name is given by
  another variable, and FAQ 7.21 tells you how, but that probably isn't a
  good idea.]

 	-thomas




More information about the R-help mailing list