How to write columns from multiple files into one dataframe

I have about 100 text files, each containing 3 columns. I want to read each file in an object and then the content into a matrix that has 300 columns.

Matrix created:

ptamat <- matrix(ncol=300, nrow=2665)

      

Reading files into an object

myfiles <- lapply(Sys.glob('pta_out__*'), read.table)

      

Show contents of first 2 files in myfiles object

myfiles[[1:2]]

      

Copy files to 'myfiles' object in matrix

ptamat[,1:300] <- myfiles[[1:100]]

      

The last part doesn't work. Any ideas?

+3


source to share


1 answer


Below are cbind

all the elements of the list:



do.call(cbind, myfiles)

      

+3


source







All Articles