Learn R Programming

permutations (version 1.1-9-1)

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

Description

Length-2 cycles; swap a pair of elements

Usage

swap(a, b)

Value

Returns a permutation in cycle form

Arguments

a, b

Integers

Author

Robin K. S. Hankin

Details

Swaps two elements. Vectorized; uses standard recycling.

See Also

as.cycle

Examples

Run this code

swap(2, 8)

swap(5, 1:9)

swap(1:8, 8:1)

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

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


Run the code above in your browser using DataLab