title: Non-numeric Argument to Binary Operator Error in R
body: <p>The issue I believe is how CurrentDay is entered. It was previously created as:</p>
  
  <pre><code>Transaction &lt;- function(PnL, Day)
    results &lt;- list(a = PnL, b = Day)
    return(results)
  </code></pre>
  
  <p>Both PnL and Day are numeric values.</p>
  
  <pre><code>Day &lt;- Transaction(PnL, Day)["b"]
  </code></pre>
  
  <p>Where Transaction returned a list and b is an integer.</p>
  
  <pre><code>moving_avg &lt;- function(StockData, MA, CurrentDay){
    #MA = Days long the MA is
    #CurrentDay = What day we are currently on
    MAValue &lt;- NULL
    total &lt;- 0
    start &lt;- CurrentDay - MA
    for(i in 1:length(MA)) {
      total &lt;- total + StockData[[start, 4]]
      start &lt;- start + 1
    }
    MAValue &lt;- total/MA
    return(MAValue)
  }
  </code></pre>
  
  <p>Anyone know why I am receiving this error?</p>
  
  <blockquote>
    <p>Error in CurrentDay - MA : non-numeric argument to binary operator</p>
  </blockquote>