There are three steps:
- Fetch all file names via
list.files
- Use
lapply to read all files in a list
- Use
do.call to rbind all data into a single data frame or matrix
The code:
nm <- list.files(path="path/to/file")
do.call(rbind, lapply(nm, function(x) read.table(file=x)[, 2]))
Subsetting with [] is arbitrary, this example is for the second columns only.