How to iterate over rows and update values and use the updated value in new iterations

  Kiến thức lập trình

I’m trying to iterate over some rows to calculate a new column, and, I want to use the result of each calculated row in the next calculation.

Example

i want to do something like this (TEST DATA

I tried some ways but, couldn’t solve it, i just want to know the main idea to try to apply it.

tried something like this

for ( i in CUSTNO) {
  
  i <- BAL + GL$CR - GL$DR

  GL$BALNCE <- i
}

I was expecting the BAL value to change after each calculation, but it remained the same

LEAVE A COMMENT