[R] Logical "and"

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Nov 11 14:44:47 CET 2004


Alexander Sokol <alexandersokol at ofir.dk> writes:

> Hello,
> 
> I have the following very simple problem:
> 
> Say I have two vectors,
> 
> a<-c(1,7,4,5,9,11)
> b<-c(7,4,9)
> 
> I would like to create a vector containing the elements in a which are not in 
> b.

As in

> setdiff(a,b)
[1]  1  5 11

or 

> a[!(a %in% b)]
[1]  1  5 11

?

(Note that they differ if a has nonunique values).

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list