invPerm: Inverse Permutation Vector

Description Usage Arguments Value Author(s) See Also Examples

Description

From a permutation vector p, compute its inverse permutation vector.

Usage

1
invPerm(p, zero.p = FALSE, zero.res = FALSE)

Arguments

p

an integer vector of length, say, n.

zero.p

logical indicating if p contains values 0:(n-1) or rather (by default, zero.p = FALSE) 1:n.

zero.res

logical indicating if the result should contain values 0:(n-1) or rather (by default, zero.res = FALSE) 1:n.

Value

an integer vector of the same length (n) as p. By default, (zero.p = FALSE, zero.res = FALSE), invPerm(p) is the same as order(p) or sort.list(p) and for that case, the function is equivalent to invPerm. <- function(p) { p[p] <- seq_along(p) ; p }.

Author(s)

Martin Maechler

See Also

the class of permutation matrices, pMatrix.

Examples

1
2
3
4
5
6
7
8
9
  p <- sample(10) # a random permutation vector
  ip <- invPerm(p)
  p[ip] # == 1:10
  ## they are indeed inverse of each other:
  stopifnot(
    identical(p[ip], 1:10),
    identical(ip[p], 1:10),
    identical(invPerm(ip), p)
  )


Search within the Matrix package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.