Skip to content
Prev 245629 / 398503 Next

A question to get all possible combinations

Dear Ron,
On Wed, Dec 22, 2010 at 1:19 PM, Ron Michael <ron_michael70 at yahoo.com> wrote:
A matrix is just a vector, so each possible sample of size 6 from df1
corresponds to a sample of size 6 from the vector 1:32.  There are
many, many ways to get all of those (there are choose(32,6) such
samples).   The way I do it is

library(prob)
urnsamples(1:32, size = 6)

and you can find lots of other, faster ways.   If you store all of
those in a data frame A, say, then you can get all possible samples
from df1 with something like

apply(A, 2, function(x) df1[x]))

The good news is that the result will also be a matrix. Each row will
be a possible sample of size 6 from df1.

Hope this helps,
Jay

P.S. Note that urnsamples by default is replace = FALSE, ordered =
FALSE, which is how I got away with the short command above.



__________________________
G. Jay Kerns, Ph.D.
Youngstown State University
http://people.ysu.edu/~gkerns/