Suppose we are given a vector foo and we have to temporarily permute it (sort or re-order it), compute some vector bar on the base
foo
bar
To recover the original order, use order(o):
order(o)
> (foo[o]*2)[order(o)] [1] 2 14 6 10 4