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.

______________________________________________
[EMAIL PROTECTED] 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

Reply via email to