'Calculate interest on Lease over time in tidyverse using Group_by and Loop

I am new to Tidyverse:

I've a data that shows like this:

Group   Run.Month2  Final.PV    Call    Draft.PV
A   30-04-2022  11922   0   7922
A   31-05-2022  11922   1   3922
A   30-06-2022  11922   1   -78
B   30-04-2022  14901   0   9901
B   31-05-2022  14901   1   4901
B   30-06-2022  14901   1   -99
C   30-04-2022  19670   0   13070
C   31-05-2022  19670   1   6470
C   30-06-2022  19670   1   -130
D   30-04-2022  44704   0   29704
D   31-05-2022  44704   1   14704
D   30-06-2022  44704   1   -296
E   30-04-2022  11922   0   7922
E   31-05-2022  11922   1   3922
E   30-06-2022  11922   1   -78
F   30-04-2022  16392   0   10892
F   31-05-2022  16392   1   5392
F   30-06-2022  16392   1   -108

Actual Data

Intended Ouput:

enter image description here

Formula in Intrest Column is :

For every start Runmonth by Group it is 0. Second Month is "Draft PV of Second Month" + "Interest of 1st Month" to be plotted. Similarly 3rd Month = "Draft PV of 3rd Month" + "Interest of 1st + 2nd Months" to be plotted.

I am finding it easy in excel using Freeze panes by tidyverse would be helpful.

Any help with R-Tidyiverse would be of great help. Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source