Skip to content
Back to formatted view

Raw Message

Message-ID: <x2mzxoijow.fsf@biostat.ku.dk>
Date: 2004-11-11T13:44:47Z
From: Peter Dalgaard
Subject: Logical "and"
In-Reply-To: <41B2867D@webmail2.ofir.dk>

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