[R] check without loop

Jason Turner jasont at indigoindustrial.co.nz
Wed Mar 20 19:40:32 CET 2002

On Wed, Mar 20, 2002 at 11:40:58AM -0500, jimi adams wrote:
> i am probably just missing this one, but how can i check to see if a number
> is a part of a vector?
> # if i draw, say 80, i would then not want to proceed, but if i draw a
> number on arclist i do

if( !(80 %in% arclist)) {...}

Getting a bit trickier, if you need to know which element it is, 
check out "which()".  e.g.  if you would only proceed if 79 was 
one of the first 20 elements

if(any(which(arclist == 79) <=20)) {...}


Indigo Industrial Controls Ltd.
jasont at indigoindustrial.co.nz
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list