I have around 100 text files each with 3 columns. I want to read every file into an object and then the contents to a matrix that has 300 columns in it.
Created a matrix:
ptamat <- matrix(ncol=300, nrow=2665)
Read files into an object
myfiles <- lapply(Sys.glob('pta_out__*'), read.table)
Show contents of first 2 files in the myfiles object
myfiles[[1:2]]
Copy files in the 'myfiles' object to the matrix
ptamat[,1:300] <- myfiles[[1:100]]
The last part does not work. Any ideas?
The following should cbind all list elements:
do.call(cbind, myfiles)
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