title: Error in function using numeric vector
body: <p>Create a function that takes in a numeric vector. The objective is to forecast using exponential smoothing. </p>
  
  <p>The formula is ( is the actual value and ̂ is the forecasted value) - ̂+1=̂+(− ̂)</p>
  
  <p>The output of the function should be a data frame with two columns – actual and predicted values. Set a default value of 0.8 for .</p>
  
  <pre><code>a1 &lt;- c(1.02, 2.21, 2.35, 3.06, 4.4, 5.2)
  f1 &lt;- c(1.05, 2.3, 3.0, 2.96, 4.1, 5.5)
  alpha &lt;- 0.8
  f2 &lt;- f1 + alpha * (a1 - f1)
  </code></pre>
  
  <p>I don't think I need a function to solve this problem. I am a rookie in R, I appreciate if anyone can let me know anything wrong in my thought. </p>
  
  <p>BTW, if I'm trying to use function to solve it,</p>
  
  <pre><code>ExpForecast = function(v,alpha = 0.8)
  {
     ResultMatrics1 = data.frame()
     for (i in 2:length(v))
     {
  
         a = data.frame(v[i],(ResultMatrics1[(i-1),2]))
                           +alpha*(v[(i-1)]-ResultMatrics1[(i-1),2])
         ResultMatrics1 = rbind(ResultMatrics1,a)
     }
     return (ResultMatrics1)
     colnames(ResultMatrics1) = c("y","y_hat")
  }
  
  ExpForecast(v=c(2,5,13,24,53))
  </code></pre>
  
  <p>There always an error prompt out.</p>