title: Flip the matrix
body: <p>Hi everyone who loves while hates R:</p>
  
  <p>Let's say you want to turn matrix M</p>
  
  <pre><code>      [,1] [,2] [,3]
  [1,]    1    2    3
  [2,]    4    5    6
  [3,]    7    8    9
  </code></pre>
  
  <p>to N</p>
  
  <pre><code>       [,1] [,2] [,3]
  [1,]    3    2    1
  [2,]    6    5    4
  [3,]    9    8    7
  </code></pre>
  
  <p>All you need to do is </p>
  
  <pre><code>N&lt;-M[,c(3:1)]
  </code></pre>
  
  <p>And N's structure is still a matrix</p>
  
  <p>However, when you want to turn matrix M</p>
  
  <pre><code>       [,1] [,2] [,3]
  [1,]    1    2     3  
  </code></pre>
  
  <p>to N</p>
  
  <pre><code>       [,1] [,2] [,3]
  [1,]    3    2     1  
  </code></pre>
  
  <p>if you do 
      N&lt;-M[,c(3:1)]
  R will give you</p>
  
  <pre><code>N
  [1] 3 2 1
  </code></pre>
  
  <p>N now is a vector! Not a matrix!</p>
  
  <p>My solution is 
      N&lt;-M%*%diag(3)[,c(3:1)] 
  which needs big space to store the identity matrix however.</p>
  
  <p>Any better idea?</p>