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)
)
Run the code above in your browser using DataLab