From J.C.Rougier@durham.ac.uk  Tue Jan  4 16:45:12 2000
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Tue, 4 Jan 2000 16:45:12 +0000 (GMT)
Subject: set functions
In-Reply-To: <x21z7xg59d.fsf@blueberry.kubism.ku.dk>
Message-ID: <Pine.GSO.4.20.0001041637120.20724-100000@laplace>

On 4 Jan 2000, Peter Dalgaard BSA wrote:

> > length(setdiff(1:4, 1:5))==0	# is TRUE
> > equiv(1:4, 1:5)			# clearly FALSE
> 
> Argh. I was thinking of the symmetric set difference. So you'd need 
> setdiff(y,x)==0 & setdiff(x,y)==0 which is obviously only half as fast
> as twice as fast....
> 
> However:
> 
> equiv<-function(x,y) 
>     length(x<-unique(x))==length(y<-unique(y)) && 
>     all(sort(x)==sort(y)) 

Yes, I wondered about that, and also about

"equiv" <-
function(x, y) {
  x <- unique(x)
  y <- unique(y)
  length(x)==length(y) && all(1:length(y) == sort(match(x, y, 0)))
}

but I thought that perhaps a sort would be more expensive than a second
call to match, and more so for two sorts.  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