It seems that I do not understand the nested for loop well enough. I am trying to work with multiple directories in a nested for loop something like this:
sp_folder1<-list.files("species1/",full.names=TRUE)
sp_folder2<-list.files("species2/",full.names=TRUE)
setwd(sp_folder1)
for(i in 1: length(sp_folder1)){
for(j in 1: length(sp_folder2){
sp_i<-read.delim(list.files(sp_folder1)[i],header=T)
sp_j<-read.delim(list.files(sp_folder2)[j],header=T)
Do something with both files
}
}
but, I am getting an error:
Error in file (file, ‘rt’): cannot open the connection
no such file or directory:
Though, the first file from ‘sp_folder1’ is fine. I tried not setting the working directory as well but still it did not work.
The easiest way would be to read the files prior to the loop. I assume that you have two subdirectories which hold the files.
(Code not tested)
Now you have two lists of data.frames, which you can access in your loops using, e.g.,
dat.list.1[[i]].