title: Running loops and receiving an error message
body: <pre><code>c &lt;- 3  # set the initial numbers
  d &lt;- acadfull[,c]
  i &lt;- 1
  p &lt;- 1
  data &lt;- data.frame()
  
  while (i &lt; 123 ) {     #loop
  
    ANS &lt;- lm(caco ~ d, data=acadfull)
  
    data[p,1] &lt;-  ANS$coefficients                             
  
    c &lt;- c+1  
    i &lt;- i+1
    p &lt;- p+1
    d &lt;- acadfull[,c]
  
    if (i==123)
      break
  
  }
  
  write.csv(c(snp,pos,data),"reg_results", row.names=F)
  </code></pre>
  
  <p>Any help would really be appreciated! When I run the above script, I get an error message saying</p>
  
  <pre><code>Error in `[&lt;-.data.frame`(`*tmp*`, p, 1, value = c(1.48484848484849,      -0.0104895104895094,  : 
    replacement has 6 rows, data has 1
  </code></pre>
  
  <p>I get the error when this line is run</p>
  
  <pre><code> ANS &lt;- lm(caco ~ d, data=acadfull)
  </code></pre>