invert.perm: Invert a permutation

Description Usage Arguments Value Note Examples

View source: R/varray_helper_functions.R

Description

For a permutation of a set of integers 1, 2, ...,p, finds the inverse permutation using the which function.

Usage

1

Arguments

perm

Vector of integers in {1:length(perm)}

Value

A vector of length length(perm) of the inverse permutation.

Note

This function won't check whether the integers you input are in the set {1:length(perm)}, but allows for length-0 entry.

Examples

1
2
3
4
5
6
7
perm <- c(5, 1, 2, 3, 4)
(perminv <- invert.perm(perm))
perm[perminv]
perminv[perm]

## The zero case:
invert.perm(integer(0))

vincenzocoia/copsupp documentation built on Aug. 23, 2020, 7:37 a.m.