title: how to find order of rows in a matrix using order function
body: <p>d&lt;-matrix(1:25,5,5) (this is just an example, the numbers will be random essentially)</p>
  
  <pre><code>     [,1] [,2] [,3] [,4] [,5]
  [1,]    1    6   11   16   21
  [2,]    2    7   12   17   22
  [3,]    3    8   13   18   23
  [4,]    4    9   14   19   24
  [5,]    5   10   15   20   25
  </code></pre>
  
  <p>I would like to apply order to each row, and get something like this:</p>
  
  <pre><code>0 1 2 3 4 
  0 1 2 3 4 
  ... 
  </code></pre>
  
  <p>I tried this: </p>
  
  <pre><code>l&lt;-apply(d,1, function(x) order(x))
  </code></pre>
  
  <p>But I get this result:</p>
  
  <pre><code>     [,1] [,2] [,3] [,4] [,5]
  [1,]    1    1    1    1    1
  [2,]    2    2    2    2    2
  [3,]    3    3    3    3    3
  [4,]    4    4    4    4    4
  [5,]    5    5    5    5    5
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>&gt; d&lt;-matrix(sample(1:25),5,5)
  &gt; d
       [,1] [,2] [,3] [,4] [,5]
  [1,]    1   20   13    4   11
  [2,]   22   17   24    3   16
  [3,]   18   23    2   15   14
  [4,]    5   25    7   10   21
  [5,]   12    8    6   19    9
  </code></pre>
  
  <p>Sorry I'm thinking of rank. The result should be something like this:</p>
  
  <p>1 5 4 2 3 (row 1) and so on:</p>
  
  <p>Please help, thank you!!</p>