title: Assign vectors to each rows of a null matrix without for loop in R
body: <p>Suppose I have a function <code>fun</code> in R, which can generate random output each time it runs.</p>
  <p>I have defined a null matrix <code>M</code> with <code>r</code> rows and <code>m</code> columns. Note that the <code>fun</code> produces object of size m.</p>
  <p>My goal is to assign randomly generated values from <code>fun</code> to each rows of <code>M</code>, <strong>without using the <code>for</code> loop.</strong></p>
  <p>I've tried something like this:</p>
  <pre><code>set.seed(200)
  
  fun=function(mu)
  {
    a=rnorm(2,mu,1)
    b=rexp(2,mu)
    return(list(&quot;A&quot;=a,&quot;B&quot;=b))
  }
  
  M=matrix(0,nrow=10,ncol=2)
  M[1:10,]=fun(5)$A
  </code></pre>
  <p>The output is as follows:</p>
  <pre><code> [,1]     [,2]
   [1,] 5.084756 5.084756
   [2,] 5.226460 5.226460
   [3,] 5.084756 5.084756
   [4,] 5.226460 5.226460
   [5,] 5.084756 5.084756
   [6,] 5.226460 5.226460
   [7,] 5.084756 5.084756
   [8,] 5.226460 5.226460
   [9,] 5.084756 5.084756
  [10,] 5.226460 5.226460
  </code></pre>
  <p>It seems that the values are repeated after every two rows. Can anyone help me to find an efficient way to do this without the <code>for</code> loop?</p>