title: Replacement has more rows than data in for loop
body: <p>First, I do realize that there is a question with a similar title, but it didn't seem to solve my problem.</p>
  
  <p>I am simply trying to build a logarithmic stock price index with log base 10 with a for loop like this:</p>
  
  <pre><code>t &lt;- nrow[dat]
  
  dat$logind &lt;- matrix(NA, t, 1)
  dat$logind[1] &lt;- 100
  
  for (i in 2:t) {
    dat$logind[i] &lt;- (dat$logind[i-1] * (1+dat$logr[i])) 
  }
  </code></pre>
  
  <p><code>dat</code> is the dataframe, <code>logind</code> is just a column that I created to hold the index, and <code>logr</code> has the logarithmic returns. However, this throws me the following:</p>
  
  <pre><code>Error in `$&lt;-.data.frame`(`*tmp*`, "logind", value = c(100, 99.3891882,  : 
    replacement has 1155 rows, data has 1154
  </code></pre>
  
  <p>I read that this error could be solved with using another way to select the column like <code>dat[,column]</code> but how do I use this when I already have <code>[i]</code> there? Or if you have another solution to this problem. Thanks.</p>