Skip to content

problem with using %in% condition while using in if() condition

3 messages · venkata kirankumar, PIKAL Petr, Greg Snow

#
Hi

r-help-bounces at r-project.org napsal dne 19.02.2009 07:15:00:
condition
SubFinSpt$SPECIMENTYP %in% CAP$SPECIMENTYP

gives you logical vector

"if" works only with the first value of this vector

see

?"if"
?"ifelse"

Regards
Petr
http://www.R-project.org/posting-guide.html
#
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.