[Rd] Multiple Intersections

Martin Maechler maechler at stat.math.ethz.ch
Wed May 28 18:14:00 CEST 2008


Please, Gentlemen,

this whole thread has *nothing* to do with  "R-devel",
and pretty much with "R-help".

So please revert to there (or do reply off-list if you really
want that)

Regards, Martin

>>>>> "TC" == Tony Chiang <tchiang at fhcrc.org>
>>>>>     on Wed, 28 May 2008 16:57:04 +0100 writes:

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

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

    TC> Cheers, --tony


    TC> On Wed, May 28, 2008 at 3:58 PM, Martin Morgan
    TC> <mtmorgan at fhcrc.org> wrote:

    >> Hi Tony -- off-list, as I think you're looking for
    >> something else...
    >> 
    >> "Tony Chiang" <tchiang at fhcrc.org> 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 at 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]]

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



More information about the R-devel mailing list