# set functions

**Martin Maechler
**
Martin Maechler <maechler@stat.math.ethz.ch>

*Wed, 5 Jan 2000 10:50:11 +0100 (MET)*

On 4 Jan 2000, Peter Dalgaard BSA wrote:
> Watch:
>
> > x<-1:50000
> > y<-x[order(runif(50000))]
> > "equiv2" <- function(x, y) all(c(match(x, y, 0)>0, match(y, x, 0)>0))
> > equiv<-function(x,y)
> + length(x<-unique(x))==length(y<-unique(y)) &&
> + all(sort(x)==sort(y))
> > system.time(equiv2(x,y))
> [1] 3.10 0.02 3.00 0.00 0.00
> > system.time(equiv(x,y))
> [1] 0.77 0.00 1.00 0.00 0.00
JonR> Yup -- that's much quicker! To re-ask the original question,
JonR> would it be reasonable to include such a function along with the
JonR> other set functions? Cheers, Jonathan.
quite a good idea, particularly, since we all have now learned that it is
non-trivial to write really efficiently.
However, I think "equiv" is not specific enough (could mean "equivalence of
arbitrary R objects").
Wouldn't "setequiv" or "setequal" be better ?
((and would you provide (to R-core) patches to
src/library/base/R/sets.R and src/library/base/man/sets.Rd))
Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._