Hi Martin,

I think I was extremely unclear about my question. If I have a list of $n$
character vectors, I would like to look at the intersection of $k$ of these
vectors (of which there are n choose k).
Martin, you methods (at least the first one) is one that I use, but I also
use the combn(n,k) and take the columns of the output to subset the original
list for which to take the multiple intersections.

Robert has pointed out (to me) that this might be a (hyper)graph function.
While I agree that the list could be represented as hyper-edges, I also tend
to think that it is a more general set theoretic issue. Personally, I am
looking at some statistics on posets, and this comes up for me. But without
any other suggestions, I will find out if I can incorporate a function into
graph or hypergraph.

Cheers,
--tony


On Wed, May 28, 2008 at 3:58 PM, Martin Morgan <[EMAIL PROTECTED]> wrote:

> Hi Tony -- off-list, as I think you're looking for something else...
>
> "Tony Chiang" <[EMAIL PROTECTED]> writes:
>
> > Hi all,
> >
> > I don't know if this is the correct venue for this question, but I am
> sure
> > that someone will correct me if I am in the wrong list.
> >
> > I have been searching throughout R for a function that can find the
> > intersection of multiple sets of "things". Say for instance, I have a
> list
> > of $n$ character vectors and would like to find the intersection of all
> $k$
> > subsets. I don't believe that there is such a function to do this (or am
> I
> > wrong?). It is a pretty easy to encode such a function...there was an
> e-mail
> > about how a recursive function to intersect an arbitrary number of sets
> > which is elegant and useful (sorry I forgot the person's name who wrote
> the
> > 2 line function).
>
> Maybe this is what you were thinking of?
>
> Intersect=function(x, ...) {
>    if (length(list(...))>1)
>        Intersect(x, Intersect(...))
>    else
>        intersect(x, ...)
> }
>
> > Intersect(letters[1:5], letters[3:6], letters[4:7])
> [1] "d" "e"
> > l=list(letters[1:5], letters[3:6], letters[4:7])
> > do.call("Intersect", l)
> [1] "d" "e"
>
> Also
>
> > Reduce(intersect, l, letters)
> [1] "d" "e"
>
> This won't be efficient for a large set of 'things', and I'm not
> getting how n and k fit in -- 'all k subsets' implies all elements of
> n?
>
> Martin
>
> > My question is two-fold:
> >
> > 1. If such a function already exists, what is it called?
> > 2. If such a function does not exists, it is worthwhile to encode it
> (i.e.
> > can I send my code to someone?).
> >
> > Cheers,
> > --tony
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Martin Morgan
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M2 B169
> Phone: (206) 667-2793
>

        [[alternative HTML version deleted]]

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

Reply via email to