combs {caMassClass} | R Documentation |
Finds all unordered combinations of k
elements from vector
v
.
combs(v,k)
v |
Any numeric vector |
k |
Number of elements to choose from vector v . Integer smaller
or equal than length of v . |
combs(v,k)
(where v
has length n
) creates a matrix with
n!/((n-k)! k!) (n
choose k
) rows
and k
columns containing all possible combinations of n
elements
taken k
at a time.
Jarek Tuszynski (SAIC) jaroslaw.w.tuszynski@saic.com
I discovered recently that R packages already have two functions with
similar capabilities:
combinations
from gTools package and
nchoosek
from vsn package.
Also similar to Matlab's nchoosek
function (
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nchoosek.html)
#example: combs(1:3,2) returns matrix with following rows (1 2), (1 3), (2 3) combs(1:3,2)