[R] Logical "and"

Wiener, Matthew matthew_wiener at merck.com
Thu Nov 11 14:39:24 CET 2004

Alexander --

a[!(a %in% b)] should do the trick.

setdiff could also probably be used.

Hope this helps,

Matt Wiener

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Alexander Sokol
Sent: Thursday, November 11, 2004 8:34 AM
To: r-help at stat.math.ethz.ch
Subject: [R] Logical "and"


I have the following very simple problem:

Say I have two vectors,


I would like to create a vector containing the elements in a which are not

Obviously, this is possible by writing

a[a!=b[1] & a!=b[2] & a!=b[3]]

But I would like a solution which is applicable to the situation where the 
number of elements in b is unknown.

I have looked in the R manuals, the FAQ and the mailing lists, but have been

unable to find a solution.

Thank you for your replies,

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list