swap: Length-2 cycles; swap a pair of elements

View source: R/permfuns.R

swapR Documentation

Length-2 cycles; swap a pair of elements

Description

Length-2 cycles; swap a pair of elements

Usage

swap(a, b)

Arguments

a, b

Integers

Details

Swaps two elements. Vectorized; uses standard recycling.

Value

Returns a permutation in cycle form

Note

If the first argument equals the second, the identity permutation is returned.

Cycles of the form (1n), that is, swap(1, n), are used extensively in inst/outer_automorphisms_of_S6.Rmd.

Author(s)

Robin K. S. Hankin

See Also

as.cycle

Examples


swap(2, 8)

swap(5, 1:9)

swap(1:8, 8:1)

swap(sample(9), sample(9))

rcyc(10,4)^swap(1,9)



permutations documentation built on July 13, 2026, 5:07 p.m.