I have something like the following data frame in R. I want to create a loop that creates a cumulative sum with with first incoming amount as the initial balance, and then subtracts when an amount is outgoing and adds when an amount is incoming. Any idea how to do this in R would be appreciated.
Seq<-c(1,2,3,4,5)
Direction<-c("INCOMING","OUTGOING", "INCOMING", "OUTGOING", "OUTGOING")
Amount<-c(500,200,300,400,200)
df<-cbind(Seq, Direction, Amount)