[R] inverse function of order()

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Mon Oct 4 16:51:45 CEST 2004


Wolfram Fischer wrote:
> I have:
> 
>  d <- sample(10:100, 9)
>  o <- order(d)
>  r <- d[o]
> 
> How I can get d (in the original order), knowing only r and o?
>

  r[order(o)]?

  > d=sample(10:100,9)
  > o=order(d)
  > r=d[o]
  > all(r[order(o)] == d)
  [1] TRUE

  tested and works for duplicates in d as well.

Barry




More information about the R-help mailing list