title: Unknown or uninitialised column when using Lag in calculation
body: <p>I am trying to refer to the previous row in the same column inside a calculation for said column. However this always leads to an 'Unknown or uninitialised column' warning message and a lot of NA's.</p>
  
  <pre><code>MovementData &lt;- c(-1, -2, -1, 1, 2, 4) 
  Database &lt;- data.frame(MovementData) 
  
  Database$Score &lt;- ifelse(Database$MovementData &lt;= 0 , 0,
                                      ifelse(lag(Database$Score,1) == 0,1,2))
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>Database$Score &lt;- c(0,0,0,1,2,2)
  </code></pre>
  
  <p>My intentions for the calculation is the following:
  If the MovementData is negative, the score is 0. If the MovementData is positive AND the previous score was 0, the score is 1. If the MovementData is positive and the previous score was not 0, the score is 2.</p>
  
  <p>This gives me the previously mentioned error. 
  I'm looking for a way to use lag (or another function) which can refer to previous rows in the Database$Score column inside the calculation of the column itself.
  How can i refer to previous rows in the same column when calculating said column?</p>