combinations enumerates the possible combinations of a specified size
from the elements of a vector.
permutations enumerates the possible
1 2 3
Size of the source vector
Size of the target vectors
Source vector. Defaults to
Logical flag indicating whether duplicates should be removed from
the source vector
Logical flag indicating whether the constructed
vectors may include duplicated values. Defaults to
Caution: The number of combinations and permutations increases rapidly with
To use values of
n above about 45, you will need to increase R's
recursion limit. See the
expression argument to the
command for details on how to do this.
Taken from an email by Brian D Ripley <email@example.com> to r-help dated Tue, 14 Dec 1999 11:14:04 +0000 (GMT) in response to Alex Ahgarin firstname.lastname@example.org. Original version was named "subsets" and was Written by Bill Venables.
Returns a matrix where each row contains a vector of length
Venables, Bill. "Programmers Note", R-News, Vol 1/1, Jan. 2001. https://cran.r-project.org/doc/Rnews/
1 2 3 4 5 6 7 8 9 10 11 12 13
combinations(3,2,letters[1:3]) combinations(3,2,letters[1:3],repeats=TRUE) permutations(3,2,letters[1:3]) permutations(3,2,letters[1:3],repeats=TRUE) ## Not run: # To use large 'n', you need to change the default recusion limit options(expressions=1e5) cmat <- combinations(300,2) dim(cmat) # 44850 by 2 ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.