Re: [R] How to do a "go to " in a loop in R

From: Gabor Grothendieck <>
Date: Thu 22 Jul 2004 - 06:17:09 EST

Lisa Wang <lisawang <at>> writes:

: Hi there,
: I'm writing a function which involves a loop. What to write in the "?"
: place would allow it skips the "for loop" and goes to "a[i]<-0".
: a<-b[s>3,]
: if (nrow(a)==0) ?????????????
: for (i in 1:nrow(a)){
: a[i]<-1
: }
: a[i]<-0

There are a number of errors in the above but I assume your question is how to set up a loop over an index of the rows of a so that the loop executes zero times if a has no rows. Try this:

  for(i in seq(len=nrow(a))) ...

Also, depending on what you want to do, you might consider whether you need a loop in the first place. mailing list PLEASE do read the posting guide! Received on Thu Jul 22 06:25:32 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:09 EST