permutations: Generate all permutations of a vector

View source: R/permutation.R

permutationsR Documentation

Generate all permutations of a vector

Description

Given the input vector, generate a matrix of permutations where each row represents a permutation of the data. Stolen from: https://stackoverflow.com/a/34287541

Usage

permutations(x)

Arguments

x

vector

Value

factorial(x) x length(x) matrix

Examples

v <- letters[1:4]
p <- permutations(v)
p

coriell-research/coriell documentation built on March 29, 2025, 2:19 p.m.