First, let me apologize in advance if this is the wrong place to submit a suggestion for a change to functions in the base-R package. It never really occurred to me that I'd have an idea worthy of such a change.

My idea is to provide an upgrade to all the "sets" tools (intersect, union, setdiff, setequal) that allows the user to apply them in a strictly algebraic style.

The current tools, as well documented, remove duplicate values in the input vectors. This can be helpful in stats work, but is inconsistent with the mathematical concept of sets and set measure. What I propose is that all these functions be given an additional argument with a default value: "multiple=FALSE" . When called this way, the functions remain as at present. When called with "multiple=TRUE," they treat the input vectors as true 'sets' of elements.

I've already written and tested upgrades to all four functions, so if upgrading the base-R package is not appropriate, I'll post as a package to CRAN. It just seems more sensible to add to the base.

Thanks in advance for any advice or comments.
(Please be sure to email, as I can't recall if I'm currently registered for r-devel)

Here's an example of the new code:

intersect<-function (x, y,multiple=FALSE)
{
    y <- as.vector(y)
        trueint <- y[match(as.vector(x), y, 0L)]
    if(!multiple) trueint <- unique(trueint)
        return(trueint)
}

thanks
Carl
-

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to