This code should work for your goal. My files are stored in a directory named FILES that is a subdiretory of the working directory.
It might be better to load all of the data frames into a list where it would be easier to iterate over them.
Thank you.
I have one more question, is there a way to remove the incorrect files or empty files?
Actually, I wrote the below code and it worked. but if there is an incorrect file it would show an error(for the first line).
fileList <- list.files(path="~/Desktop/ project/EpiRegio", pattern=".txt")
sapply(fileList, read.delim)
mainlist = list()
for (i in 1: length(fileList)) {
mainlist[[i]] = read.delim(fileList[i], header = TRUE, sep = "\t")
}
In my last post I was fixing the error thrown wehn reading an empty file. The error was not thrown by list.files but by read.delim. Can you please post your exact coe and the text of the error you see?