So, I uploaded a dataset containing 900 txt files, one for each biological sample. I want to combine all this data into one data matrix in R.
txt_files = list.files() # read txt files into a list for (i in length(txt_files)){ x <- read.table(file=txt_files[i], sep="\t", header=TRUE, row.name=1) }
All files are in the same folder, so I use list.files() to query all file names. Then I want to read each table into a separate R-object (which in this case is called x). The problem is that I would like to name each object after the name of the actual file instead of x.
I tried a couple of things and tried to search the Internet, but have not yet found a solution. One thing I found is to use lapply to import them all into a data list.
data_list = lapply(txt_files, read.table, sep = "\t")
However, I donβt think it would be appropriate for me, since after that the data matrices are no longer available. I hope someone can help me.
source share