title: R - Avoiding for loops based on matrix indices
body: <p>I would like to know if it's possible to do the following trick avoiding <code>for</code> loops maybe using smoehow <code>apply</code>, but I dunno how to do in this case with that <code>max(i-4,1)</code></p>
  
  <pre><code>x &lt;- matrix(seq_len(100),10,10)
  x[,1] &lt;- letters[1:10] 
  y &lt;- x
  for (i in 1:nrow(x)) {
    for (j in 2:ncol(x)) {
      y[i,j] &lt;- x[max(i-4,1),j]
    }
  }
  </code></pre>