On 11-05-24 6:00 AM, Alaios wrote:
Dear all,
I would like to do read a bunch of files that have the following format

file_i_j
examples:
file_1_1
file_1_2
file_1_3
file_2_1
file_2_2
file_3_1
file_3_2
file_3_3
file_3_4
file_4_1
file_4_2

The integer i goes from 1 to 100
and the integer j starts from 1 and stops somewhere between 1 and 100, which I 
do not know in advance

Usually I would be able to solve this by having a nested loop

(algorithmic syntax below, not sure if is R okay)
for i in (c(1:100))
   for j in (c(1:100))
     store[i,j]<- read file_i_j
    end
end

the problem with that is that R will halt when j take a value that refers to a 
non existing value. Thus I want to have a good way to break the nested loop and 
continue with the outer one. How I can do that?

Use a while() loop, or use break. You can test for the existence of a file using the file.exists() function.

Duncan Murdoch

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to