Getting the excluded elements for each of the combn(n,k) combinations
Posted
by gd047
on Stack Overflow
See other posts from Stack Overflow
or by gd047
Published on 2010-03-22T08:49:55Z
Indexed on
2010/03/22
8:51 UTC
Read the original article
Hit count: 399
r
|combinations
Suppose we have generated a matrix A
where each column contains one of the combinations of n
elements in groups of k
. So, its dimensions will be k,choose(n,k)
. Such a matrix is produced giving the command combn(n,k)
. What I would like to get is another matrix B
with dimensions (n-k),choose(n,k)
, where each column B[,j]
will contain the excluded n-k
elements of A[,j]
.
Here is an example of the way I use tho get table B
. Do you think it is a safe method to use? Is there another way?
n <- 5 ; k <- 3
(A <- combn(n,k))
(B <- combn(n,n-k)[,choose(n,k):1])
That previous question of mine is part of this problem.
Thank you.
© Stack Overflow or respective owner