[R] question about setdiff()

Liaw, Andy andy_liaw at merck.com
Fri Feb 27 19:35:37 CET 2004


`Same' object appearing more than once do not count, I guess.  As an
example:

> setdiff(c(1,2,2), c(3,4))
[1] 1 2

The second `2' does not show up, because

> setdiff
function (x, y) 
unique(if (length(x) || length(y)) x[match(x, y, 0) == 0] else x)
<environment: namespace:base>

Note the unique().

Andy

> From: Svetlana Eden
> 
> 
> Thank you for your answers,
> I have another question:
> 
> the behaviour of setdiff(indicesFalse, indicesNA)
> does not seem predictable to me.
> 
> 
> > indices
> [1] 1 2 3 4 5 6
> > compareVector
> [1]    NA  TRUE  TRUE  TRUE FALSE    NA
> >   indicesNA = indices[is.na(compareVector)]
> >   indicesNA
> [1] 1 6
> >   indicesFalse = indices[compareVector == FALSE]
> >   indicesFalse
> [1] NA  5 NA
> >   setdiff(indicesNA, indicesFalse) ######################## OK
> [1] 1 6
> >   setdiff(indicesFalse, indicesNA) ######################## I would
> >   expect here 'NA 5 NA'
> [1] NA  5
> >
> 
> 
> -- 
> Svetlana Eden        Biostatistician II            School of Medicine
>                      Department of Biostatistics   Vanderbilt 
> University
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list