title: for loop only showing result of one case in R
body: <p>I intend to fill a matrix I created that has 1000 rows and 2 columns. Here B is 1000.</p>
  
  <pre><code>resampled_ests &lt;- matrix(NA, nrow = B, ncol = 2)
  names(resampled_ests) &lt;- c("Intercept_Est", "Slope_Est")
  </code></pre>
  
  <p>I want to fill it using a for loop looping from 1 to 1000.</p>
  
  <pre><code>ds &lt;- diamonds[resampled_values[b,],] 
  </code></pre>
  
  <p>Here, each of the ds(there should be 1000 versions of it in the for loop) is a data frame with 2 columns and 2000 rows. and I would like to use the <code>lm()</code> function to get the Beta coefficients of the two columns of data.</p>
  
  <pre><code>for (b in 1:B) {
  #Write code that fills in the matrix resample_ests with coefficent estimates.
    ds &lt;- diamonds[resampled_values[b,],]
    lm2 &lt;- lm(ds$price~ds$carat, data = ds)
    rowx &lt;- coefficients(lm2)
    resampled_ests &lt;- rbind(rowx)
  }
  </code></pre>
  
  <p>However, after I run the loop, <code>resampled_ests</code>, which is supposed to be a matrix of 1000 rows only shows 1 row, 1 pair of coefficients. But when I test the code outside of the loop by replacing b with numbers, I get different results which are correct. But by putting them together in a for loop, I don't seem to be row binding all of these different pairs of coefficients. Can someone explain why the result matrix <code>resampled_ets</code>is only showing one result case(1 row) of data?</p>