title: R function only the last value of a vector is printed
body: <p>Thank you for your help with this function, which should :</p>
  
  <ol>
  <li>Enter a a specific value</li>
  <li>Insert the value in a function</li>
  <li>Take a set of other values generated in a vector</li>
  <li>Calculate a value for each element of a vector</li>
  <li>Return a data frame with both vector and calculated values.</li>
  </ol>
  
  <p>Here is what I tried:</p>
  
  <pre><code>rate&lt;-function(Y2) {
     ran&lt;-seq(0.001,1,0.001)
     for(i in ran) {
       calculated&lt;-as.vector(Y2/(1+i)+Y2/(1+i)^2+Y2/(1+i)^3+Y2/(1+i)^4)
       tableau&lt;-data.frame(ran,calculated)
     }
     return(tableau)
  }
  </code></pre>
  
  <p>When testing with <code>res&lt;-rate(500)</code>, only the last value is returned 1000 times:</p>
  
  <pre><code>...
  
  ran calculated
  1   0.001   468.75
  2   0.002   468.75
  3   0.003   468.75
  ...
  
  996  0.996     468.75
  997  0.997     468.75
  998  0.998     468.75
  999  0.999     468.75
  1000 1.000     468.75
  </code></pre>
  
  <p>What is wrong with my loop?</p>