-----Original Message-----
From: Yuelin Li [mailto:yuelin at mail.med.upenn.edu]
Sent: Wednesday, August 28, 2002 12:28 PM
To: r-help at stat.math.ethz.ch
Subject: [R] 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._._._._._._