title: How do I create an empty matrix in R and update it using a for loop?
body: <p>I think this is supposed to be easy but I have been stuck at this for sometime. I need to update a matrix with every loop as follows:</p>
  
  <pre><code>          r &lt;- 4
            nlag &lt;- 2
  
            for (i in 1:nlag){
              a  &lt;- ((i-1)*r)+1
              b  &lt;- i*r
              g  &lt;- beta_OLS[c(a:b),1:r]
              bb &lt;- as.vector(t(g))
            }
  </code></pre>
  
  <p>How do I update the matrix bb with g after every loop?</p>
  
  <p>The beta_OLS matrix looks like this:</p>
  
  <pre><code>    [1,]  0.603443440  0.30405670 -0.002150462  0.0090527541
      [2,] -0.003498807  0.16163517  0.056313146  0.0007139815
      [3,]  0.319393118  0.13560199  1.079001883  0.0842017718
      [4,] -0.043669654 -0.92507425 -0.173706846  0.9019772828
      [5,]  0.259785125  0.04053008  0.036206682 -0.0217682012
      [6,]  0.029130279  0.13336440  0.034382991  0.0032809117
      [7,] -0.277746555 -0.25636900 -0.173245066 -0.0636151668
      [8,]  0.046002342  0.48681546  0.131194993 -0.0563989161
  </code></pre>
  
  <p>And I want the output to be look like this in bb:</p>
  
  <p>Every 4 X 1 section stacked one on top of the other.</p>
  
  <pre><code>     0.6034
      -0.0035
       0.3195
       0.0437
       0.3041
       0.1616
       0.1356
       0.9251
      -0.0022
       0.0563
       1.0790
       0.1737
      -0.0091
      -0.0007
      -0.0842
       0.9020
       0.2598
       0.0291
      -0.2778
      -0.0460
       0.0405
       0.1334
      -0.2564
      -0.4868
       0.0362
       0.0344
      -0.1733
      -0.1312
       0.0218
      -0.0033
       0.0636
      -0.0564
  </code></pre>
  
  <p>What does it take to create an empty matrix in R, MATLAB code for which is as simple as this?</p>
  
  <pre><code>    bb = [];
  </code></pre>