[R] Is variable in one vector part of variable in another

Dr. S. B. Nguah sbnguah at yahoo.com
Sat May 31 15:48:17 CEST 2008




darthgervais wrote:
> 
> I have 2 vectors x & z
> x  has 10 variables in it
> z has 75 variable in it
> 
> I need to check all 75 variables in z and see if they are present in the
> vector x.
> So far this is what I have:
> 
> for (i in 0:75){
> if (z[i]==x) (w=w+1)
> }
> 
> Thanks in advance
> w
> 

Try:
any(!(z%in%x)   # if TRUE then extract with 
z[!(z%in%x)]

-----
Blay S
KATH
Kumasi, Ghana.
-- 
View this message in context: http://www.nabble.com/Is-variable-in-one-vector-part-of-variable-in-another-tp17574954p17575410.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list