[R] compare 2 vectors
Romain Francois
rfrancois at mango-solutions.com
Thu Jun 28 12:55:54 CEST 2007
Christophe Pallier wrote:
> On 6/28/07, João Fadista <Joao.Fadista at agrsci.dk> wrote:
>
>> I would like to take out the values from one vector that are equal to the
>> values in another vector.
>>
>> Example:
>> a <- c(1,2,3,4,5,6,7,8,9)
>> b <- c(3,10,20,5,6)
>> b_noRepeats = c(10,20)
>>
>>
>>
> b[!(b %in% intersect(a,b))]
>
> See ?intersect
>
Hi,
There is also a pretty useful operator %w/o% in the help page of %in%. see :
> ?`%in%`
> a <- c(1,2,3,4,5,6,7,8,9)
> b <- c(3,10,20,5,6)
> b %w/o% a
[1] 10 20
Cheers,
Romain
--
Mango Solutions
data analysis that delivers
Tel: +44(0) 1249 467 467
Fax: +44(0) 1249 467 468
Mob: +44(0) 7813 526 123
More information about the R-help
mailing list