>> input <- do.call(rbind, lapply(fileNames, function(.name){ > + .data <- read.table(.name, header = TRUE, as.is = TRUE) > + # add file name to the data > + .data$file <- .name > + .data > + }))
You can simplify this a little with plyr: fileNames <- list.files(pattern = "file.*.csv") names(fileNames) <- fileNames input <- ldply(fileNames, read.table, header = TRUE, as.is = TRUE) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.