I have n files, file_1, file_2, ..., file_n that I want to import and work with. So I import files like this
files <- list.files(pattern=".txt$")
for(i in files) {
x <- read.table(i, header=TRUE, comment.char = "A", sep="\t")
assign(i, x)
}
The thing is, I want to use data from different files at the same time. For example, I want to calculate the means vector of the first column of each file:
meanv = mean(file_1$firstcolumn, file_2$firstcolumn, ..., file_n$firstcolumn).
The most logical way to do it - write a loop that passes through all of the files ( file_1, file_2, ..., file_n). In this case, you need to index the files. Are there any solutions? Or there is another solution.
source
share