Learn R Programming

StatMethRank (version 1.3)

generate.perms: Generate all possible permutations of k elements out of n

Description

This function generates all permutations of n elements taken k at a time. The most efficient way to generate n! permutations of vec in a Lexicographic order without recursive algorithm in R.

Usage

generate.perms(n, k = n, vec = 1:n)

Arguments

n
number of the whole elements
k
number of elements to permute (default the same as n)
vec
the source vector of length n (default as c(1:n))

Value

a matrix or a vector, each row is a permutation

See Also

generate.combn

Examples

Run this code
generate.perms(10, 6)

Run the code above in your browser using DataLab