title: Better alternatives For Loop R
body: <p>I am storing a value in column c based on this criteria. There are 4million rows in my dataframe and this takes 2 days to finish.</p>
  
  <pre><code>for ( i in 1:NROW(df)) {
    df$c[i+1] &lt;- df$a[i] + df$b[i] - df$a[i+1]
    print(i)
  }
  </code></pre>
  
  <p>Are there any alternatives to this for loop that can accomplish what I am doing much faster. Thanks in advance.</p>