From p.dalgaard@biostat.ku.dk  Tue Jan  4 16:39:58 2000
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 04 Jan 2000 17:39:58 +0100
Subject: set functions
In-Reply-To: Jonathan Rougier's message of "Tue, 4 Jan 2000 16:17:33 +0000 (GMT)"
References: <Pine.GSO.4.20.0001041612590.20724-100000@laplace>
Message-ID: <x21z7xg59d.fsf@blueberry.kubism.ku.dk>

Jonathan Rougier <J.C.Rougier@durham.ac.uk> writes:

> On 4 Jan 2000, Peter Dalgaard BSA wrote:
> 
> > > "equiv" <- function(x, y) all(c(match(x, y, 0)>0, match(y, x, 0)>0))
> 
> > length(setdiff(x,y))==0 appears to be about twice as fast....
> 
> But I don't think that would be right!
> 
> 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)) 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
Peter Dalgaard BSA