Re: [R] skip reading a file.

From: Kenn Konstabel <lebatsnok_at_gmail.com>
Date: Tue, 24 May 2011 14:18:40 +0300

You might use dir() to get the file names (if they are in the same folder), or something like dir(pattern="^file.*") if you want to read only some files from there. Then for storing the result as something like store[i,j] as in your example, you could split the file name using something like strsplit(filename, "_") and use the resulting components for i and j.

Best regards,
Kenn

On Tue, May 24, 2011 at 1:00 PM, Alaios <alaios_at_yahoo.com> 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?
>
> Best Regards
> Alex
>
> ______________________________________________
> R-help_at_r-project.org 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.
>



R-help_at_r-project.org 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. Received on Tue 24 May 2011 - 11:22:04 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 May 2011 - 11:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive