[Rcpp-devel] setdiff
Hadley Wickham
h.wickham at gmail.com
Fri Nov 16 13:54:57 CET 2012
> I've commited an initial version of setdiff.
Cool - thanks! It might be useful in general to expose some of the
STL sorted range commands - I'm not sure if that's general enough for
base Rcpp or not.
> There is room for improvement given the R version:
>
>> setdiff
> function (x, y)
> {
> x <- as.vector(x)
> y <- as.vector(y)
> unique(if (length(x) || length(y))
> x[match(x, y, 0L) == 0L]
> else x)
> }
>
> 'initial' because it does not yet deal with missing values correctly.
>
>
>
> Is the behavior of R's setdiff what we would want to reproduce:
>
>> setdiff( c(1), c(NA,1) )
> numeric(0)
>
> # that looks odd
>> setdiff( c(1), c(NA,2) )
> [1] 1
>
> # this too
>> setdiff( c(1,NA), c(1,2) )
> [1] NA
>
> # not sure what we should expect
>> setdiff( c(NA_integer_), c(NA_integer_) )
> integer(0)
That seems reasonable to me. What are you thinking?
Hadley
--
RStudio / Rice University
http://had.co.nz/
More information about the Rcpp-devel
mailing list