permutation {truecluster} | R Documentation |
Calculating and creating permutations
npermutation(k, n, replace = FALSE) permutation(k, n=NULL, x=NULL, replace = FALSE)
k |
number of positions |
n |
poolsize |
x |
vector pool of values, can be given instead of n |
replace |
default FALSE, TRUE to allow reusing of pool elements |
npermutation
returns the number of permutations, permutation
returns a matrix of permutations. No special sequence granted. Implemented in C, but not faster than the functions in gregmisc.
A matrix of (k x npermutation)
Jens Oehlschlägel
combination
, margination
, expand.grid
, combinations
npermutation(2,4) permutation(2,4) permutation(2,x=letters[1:4]) npermutation(2,4,replace=TRUE) permutation(2,4,replace=TRUE) ## Not run: ## regression test (error in gregmisc for 1.5.1) require(gregmisc) k <- 3 n <- 6 replace <- FALSE a <- sort(apply(permutation(k,n,replace=replace), 2, paste, collapse="-")) b <- sort(apply(permutations(n,k,rep=replace), 1, paste, collapse="-")) stopifnot(length(a)==npermutation(k,n,replace=replace)) stopifnot(identical(a,b)) replace <- TRUE a <- sort(apply(permutation(k,n,replace=replace), 2, paste, collapse="-")) b <- sort(apply(permutations(n,k,rep=replace), 1, paste, collapse="-")) stopifnot(length(a)==npermutation(k,n,replace=replace)) stopifnot(identical(a,b)) ## End(Not run)