How to concatenate matrices from list
<p>I have one question.</p>

<p>I have code:</p>

<pre><code>RootBootstrapping &lt;- function(mean, sd)
{
  polyCoeffs &lt;- rnorm(length(mean), mean = mean, sd = sd);

  rawResult &lt;- as.complex(polyroot(polyCoeffs));
  roots &lt;- rawResult[order(Re(rawResult), Im(rawResult))];

  rootMatrix &lt;- matrix(nrow = (length(polyCoeffs) - 1), ncol = 2);
  colnames(rootMatrix) &lt;- c("Re", "Im");

  rootMatrix[,"Re"] &lt;- Re(roots);
  rootMatrix[,"Im"] &lt;- Im(roots);

  return (rootMatrix);
}

points &lt;- 5
polyMatrixCoeff &lt;- matrix(c(1, 0, 0.5, 0.01, 0.3, 0.02), nrow = 3, ncol = 2);
colnames(polyMatrixCoeff) &lt;- c("mean", "sd");

meanRoots &lt;- as.complex(polyroot(polyMatrixCoeff[,"mean"]));

rootsCount &lt;- length(polyMatrixCoeff[,"mean"]) - 1;
</code></pre>

<p>I want to concatenate "byrow" result from many runs of RootBootstrapping - I want to have Nx2 matrix with "Re" and "Im" columns. </p>

<p>But code below doesn't work well...</p>

<pre><code>rootsMatrix &lt;- rbind(sapply(1:points, function(i) 
                    { 
                       roots &lt;- RootBootstrapping(mean = polyMatrixCoeff[,"mean"], sd = polyMatrixCoeff[,"sd"]);
                       print(roots);
                       return (roots);
                    })
                    ); 
rootsMatrix
</code></pre>

<p>Running this code I have:</p>

<pre><code>             Re        Im
[1,] -0.8396051 -1.614007
[2,] -0.8396051  1.614007
             Re        Im
[1,] -0.8826579 -1.650071
[2,] -0.8826579  1.650071
             Re        Im
[1,] -0.8182654 -1.600865
[2,] -0.8182654  1.600865
             Re        Im
[1,] -0.7379369  1.566913
[2,] -0.7379369 -1.566913
             Re        Im
[1,] -0.7958687 -1.575169
[2,] -0.7958687  1.575169
&gt; 
&gt; rootsMatrix 
           [,1]       [,2]       [,3]       [,4]       [,5]
[1,] -0.8396051 -0.8826579 -0.8182654 -0.7379369 -0.7958687
[2,] -0.8396051 -0.8826579 -0.8182654 -0.7379369 -0.7958687
[3,] -1.6140074 -1.6500706 -1.6008651  1.5669132 -1.5751692
[4,]  1.6140074  1.6500706  1.6008651 -1.5669132  1.5751692
&gt; 
</code></pre>

<p>but I want this:</p>

<pre><code>             Re        Im
[1,] -0.8396051 -1.614007
[2,] -0.8396051  1.614007
[3,] -0.8826579 -1.650071
[4,] -0.8826579  1.650071
[5,] -0.8182654 -1.600865
[6,] -0.8182654  1.600865
[7,] -0.7379369  1.566913
[8,] -0.7379369 -1.566913
[9,] -0.7958687 -1.575169
[10,] -0.7958687  1.575169
</code></pre>

<p>So, what should I do for "byrow" matrices concatenation?</p>

<p>Thank you.</p>