Learn R Programming

nptest (version 1.2)

permn: Generate All Permutations of n Elements

Description

Generates all \(n!\) vectors of length \(n\) consisting of permutations of the integers 1 to \(n\).

Usage

permn(n)

Value

Matrix of dimension \(n\) by \(n!\) where each column contains a unique permutation vector.

Arguments

n

Number of elements.

Author

Nathaniel E. Helwig <helwig@umn.edu>

Warning

For large n this function will consume a lot of memory and may even crash R.

Details

Adapted from the "permutations" function in the e1071 R package.

References

Meyer, D., Dimitriadou, E., Hornik, K., Weingessel, A., & Leisch, F. (2018). e1071: Misc Functions of the Department of Statistics, Probability Theory Group (Formerly: E1071), TU Wien. R package version 1.7-0. https://CRAN.R-project.org/package=e1071

Examples

Run this code
permn(2)
permn(3)

Run the code above in your browser using DataLab