title: Add column with index starting at 100 to stock prices/returns matrix
body: <p>I've recently begun to use R for doing calculations with financial data, so please bear with me. I'll try to be as specific as possible.</p>
  
  <p><strong>What I'm trying to do:</strong> Using R with the quantmod package, I load financial data into a matrix and then add a column with the daily returns, as follows:</p>
  
  <pre><code>&gt; getSymbols("^GDAXI",from="1900-01-01")
  &gt; "GDAXI"
  &gt; GDAXI$Returns&lt;-dailyReturn(Cl(GDAXI))
  &gt; head(GDAXI)
                 GDAXI.Open GDAXI.High GDAXI.Low GDAXI.Close GDAXI.Volume GDAXI.Adjusted  Returns
  1990-11-26     1466.3     1466.3     1443.2    1443.2      0            1443.2          0.000000000
  1990-11-27     1438.3     1438.3     1415.3    1415.3      0            1415.3         -0.019332040
  1990-11-28     1410.0     1431.9     1402.8    1420.6      0            1420.6          0.003744789
  1990-11-29     1420.4     1424.6     1415.8    1418.9      0            1418.9         -0.001196677
  1990-11-30     1421.5     1443.9     1421.5    1441.2      0            1441.2          0.015716400
  1990-12-03     1470.1     1476.6     1458.7    1462.6      0            1462.6          0.014848737
  </code></pre>
  
  <p>However, next I would like to <strong>add another column with an index starting at 100 for later comparisons with another time series</strong>. I have not been able to do so.</p>
  
  <p>First, I tried </p>
  
  <pre><code>GDAXI$Index[1]=100
  for(i in 2:nrow(GDAXI)){ GDAXI$Index[i]&lt;-GDAXI$Index[i-1]*(1+GDAXI$Returns[i]) }
  </code></pre>
  
  <p>But I get this error message, which I don't understand:</p>
  
  <pre><code>Error in NextMethod(.Generic) : replacement has length zero
  </code></pre>
  
  <p>Then, I tried</p>
  
  <pre><code>&gt; GDAXI$Index&lt;-ifelse(index(GDAXI$Returns)==index(first(GDAXI)),100,lag(GDAXI$Index,1)*(1+GDAXI$Returns))
  </code></pre>
  
  <p>and get another error message:</p>
  
  <pre><code>Error in hasTsp(x) : attempt to set an attribute on NULL
  </code></pre>
  
  <p>All I want is a column with the following values (added manually as illustration):</p>
  
  <pre><code>1990-11-26  100.00
  1990-11-27   98.066796
  1990-11-28   98.4340255
  1990-11-29   98.3162417
  1990-11-30   99.8614191
  1990-12-03  101.344235
  </code></pre>
  
  <p>Please help! Having previously coded in VBA I'm probably approaching this the wrong way. But searching the web and stackoverflow hasn't led me to the solution, yet. Thank you very much!</p>