title: How to shift each row of a matrix in R
body: <p>I have a matrix of this form:</p>
  
  <pre><code>a b c
  d e 0
  f 0 0
  </code></pre>
  
  <p>and I want to transform it into something like this:</p>
  
  <pre><code>a b c
  0 d e
  0 0 f
  </code></pre>
  
  <p>The shifting pattern is this: </p>
  
  <pre><code>shift by 0 for row 1
  shift by 1 for row 2
  shift by 2 for row 3
  ...
  shift by n-1 for row n
  </code></pre>
  
  <p>This can be done with a for loop of course. I am wondering if
  there is a better way?</p>