Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.OSF.4.33.0208281214570.279949-100000@pobox.upenn.edu>
Date: 2002-08-28T16:28:28Z
From: Yuelin Li
Subject: all possible subsets of r out of n

Has anyone written a function that returns all possible
subsets of r elements out of a vector that contains n
elements?  I have not been able to find an answer in the FAQ
or the archives.

Say I have a vector: letters[1:10].  I want to get a matrix
of 120 rows that contains all possible subsets of 3 letters
out of the 10.  And I would like to be able to generalize to
any r out of n, like function(x=letters[1:10], r=3) that
returns:

a, b, c
a, b, d
a, b, e
...

etc.

Many thanks in advance,

- Yuelin Li.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._