I have a data frame with two rows that represent passengers loading onto the bus and passengers leaving the bus:
A B C D E F
In 9 10 6 9 14 10
Out 0 1 2 3 4 3
And I wanted to do a calculation that will result in two more rows of information, where the first is passengers who are on the bus when it arrives at Station A/B/C/etc, and Row 2 is the number of passengers who have left the bus at that station.
The numbers in row 1 should be the same from the previous number in row 2, and row 2 for Station B, for example, is `9 (the number of people who remained on the bus from the previous stop) + BIn (the number of people getting on at the stop) - BOut (the number of people who are getting off the bus at the stop).
The final result should look like:
A B C D E F
In 9 10 6 9 14 10
Out 0 1 2 3 4 3
1 0 9 18 22 28 38
2 9 18 22 28 38 45
How would I iterate through the data frame so that I can obtain these numbers? Is a for loop needed, or is there an easier way to go through this calculation?