title: can lapply not modify variables in a higher scope
body: <p>I often want to do essentially the following:</p>
  
  <pre><code>mat &lt;- matrix(0,nrow=10,ncol=1)
  lapply(1:10, function(i) { mat[i,] &lt;- rnorm(1,mean=i)})
  </code></pre>
  
  <p>But, I would expect that mat would have 10 random numbers in it, but rather it has 0. (I am not worried about the rnorm part. Clearly there is a right way to do that. I am worry about affecting mat from within an anonymous function of lapply) Can I not affect matrix mat from inside lapply? Why not? Is there a scoping rule of R that is blocking this?</p>