From: Gabor Grothendieck <ggrothendieck_at_myway.com>

Date: Thu 22 Jul 2004 - 06:17:09 EST

R-help@stat.math.ethz.ch mailing list

https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 22 06:25:32 2004

Date: Thu 22 Jul 2004 - 06:17:09 EST

Lisa Wang <lisawang <at> uhnres.utoronto.ca> 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.

R-help@stat.math.ethz.ch mailing list

https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html 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
*