I have folder, which contain around 200 .txt files. I want to read all of the files and select second column of each of them and put them in one matrix. (rbind()) is there any command to read all files at once ?
I want to use :
data<-read.table ("", header= T, sep=",")
There are three steps:
list.files
lapply to read all files in a listdo.call to rbind all data into a single data frame or matrixThe 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With