Learn R Programming

nuggets (version 2.2.3)

permute: Generate all permutations of a vector

Description

This function generates all possible permutations of the elements in a given vector x. The result is returned as a matrix, where each row represents a unique permutation of the input vector.

Usage

permute(x)

Value

A matrix where each row is a unique permutation of the input vector x.

Arguments

x

A vector of elements to permute. The elements can be of any type, but they should be unique for meaningful permutations.

Author

Michal Burda

See Also

utils::combn() for combinations of elements.

Examples

Run this code
permute(c(1, 2, 3))
permute(c("a", "b", "c"))

Run the code above in your browser using DataLab