The %in% operator returns a vector of logicals the same length as the vector to 
the left. The if program flow operator expects a single logical value, not a 
vector, since you are giving it a vector it looks at just the 1st element, 
ignores the rest and gives the warning.  This warning should be taken seriously 
since it indicates that what is happening and what you intend probably do not 
match.  

If you tell us more about what you are trying to do, we can give more help.

Some possibilities:  use any() or all() to reduce the vector to a single 
logical value.
Use ifelse(), subscripting, or some other method to accomplish what you want.


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of venkata kirankumar
> Sent: Wednesday, February 18, 2009 11:15 PM
> To: r-help@r-project.org
> Subject: [R] problem with using %in% condition while using in if()
> condition
> 
> Hi all,
> I got one problem with using %in% condition while using in if()
> condition
> where
> I used the condition as
> 
> 
> if(SubFinSpt$SPECIMENTYP %in% CAP$SPECIMENTYP)
> 
> this   "if()"    condition is in      "else"     condition
> and hear  "*SubFinSpt$SPECIMENTYP*" having only one value   but
> "*CAP$SPECIMENTYP"
> *having nearly 20 SPECIMENTYP's
> 
> while applying this condition I got one warning that says  only first
> element is checked
> and after that warning it is executing normally and giving results
> but i want to know why it is giving this warning
> 
> can any one explain why it is comming and how to resolve it
> 
> thanks in advance
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@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@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.

Reply via email to