[Rcpp-devel] setdiff
Romain Francois
romain at r-enthusiasts.com
Fri Nov 16 11:29:48 CET 2012
Hello,
I've commited an initial version of setdiff.
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)
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy
blog: http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible
More information about the Rcpp-devel
mailing list