From J.C.Rougier@durham.ac.uk  Wed Jan  5 12:10:19 2000
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Wed, 5 Jan 2000 12:10:19 +0000 (GMT)
Subject: set functions
In-Reply-To: <14451.5075.867165.954414@gargle.gargle.HOWL>
Message-ID: <Pine.GSO.4.20.0001051145270.21562-100000@laplace>

On Wed, 5 Jan 2000, Martin Maechler wrote:

> quite a good idea, particularly, since we all have now learned that it is
> non-trivial to write really efficiently.

And I've just noticed that Peter's ultra-quick sorting algorithm stumbles
over NAs:

"setequal" <- function(x,y)
  length(x<-unique(x))==length(y<-unique(y)) && all(sort(x)==sort(y))

"setequal2" <- function(x, y) all(c(match(x, y, 0)>0, match(y, x, 0)>0))

setequal(c(NA, 1:4), c(1:4, NA))	# TRUE
setequal2(c(NA, 1:4), c(1:4, NA))	# TRUE

setequal(c(NA, 1:4), c(1:4, 5))		# FALSE plus warning message
setequal2(c(NA, 1:4), c(1:4, 5))	# FALSE

Putting na.last=TRUE in sort does not help, as then there is a missing
logical for the && following the call to all.  Might I suggest, in the
light of Brian's comments, that setequal2 is more in the spirit of the
other set functions?

Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE

"[B]egin upon the precept ... that the things we see are to be 
 weighed in the scale with what we know"  (Meredith, 1879, The Egoist)

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


set functions
Jonathan Rougier