I have n files, file_1, file_2,..., file_n that I want to import and work with. So I import the 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 point is that I want to use data simultaneously from the different files. For example I want to compute 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 this is the write a loop going through all files (file_1
, file_2
,..., file_n
). In this case you need to index the files. Is there any solution to this? Or is there any other solution.