I hope you are all doing fine. Beginner here.
I have this code to get the number of rows and the mean of a column of an excel file.
data <- read.table("filename.xls",sep = "\t", header = T)
mean <- mean(data$Perim.)
ncells <- nrow(data)
df <- data.frame (mean,ncells)
write.table(df, file = "data.csv")`
I would like to find a way of running that code for all excel files in a folder, so I created a list of the excel files I would like the code applied to:
file.list <- list.files(pattern='*.xls')
But I can't even get past this part of the loop:
for(i in 1:length(file.list)){
data[i] = read.table("file.list[[i]]",sep = "\t", header = T)
}
I get the following error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'file.list[i]': No such file or directory
Could someone please explain this error and help build the rest of the loop? Very much appreciated.