invert_perm: Invert a permutation.

Description Usage Arguments Value Examples

View source: R/match_order.R

Description

For a permutation p build q such that p[q] == q[p] == seq_len(length(p)). Please see https://win-vector.com/2017/05/18/on-indexing-operators-and-composition/ and https://win-vector.com/2017/09/02/permutation-theory-in-action/.

Usage

1

Arguments

p

vector of length n containing each of seq_len(n) exactly once.

Value

vector q such that p[q] == q[p] == seq_len(length(p))

Examples

1
2
3
4
5
6
p <- c(4, 5, 7, 8, 9, 6, 1, 3, 2, 10)
q <- invert_perm(p)
p[q]
all.equal(p[q], seq_len(length(p)))
q[p]
all.equal(q[p], seq_len(length(p)))

WinVector/wrapr documentation built on Nov. 21, 2020, 8:31 p.m.