I've got a df and i need to perform a rolling sum in another dataframe based on the values of the first df
- All the transactions of each company, by date & account
- This is the dataframe I want to build with the balance at the end of the day with each company's account
| Date | Company | Account | Value |
|---|---|---|---|
| 2021-01-01 | A | a | 10 |
| 2021-01-01 | A | b | 10 |
| 2021-01-01 | A | b | 5 |
| 2021-01-02 | A | a | 12 |
| 2021-01-02 | A | a | 4 |
| 2021-01-02 | A | b | 4 |
| Date | Company | Account | Value |
|---|---|---|---|
| 2021-01-01 | A | a | 10 |
| 2021-01-01 | A | b | 15 |
| 2021-01-02 | A | a | 26 |
| 2021-01-02 | A | b | 14 |
| 2021-01-01 | B | x | i |
| 2021-01-01 | B | y | i |
| 2021-01-02 | B | x | ii |
| 2021-01-02 | B | y | ii |
In Excel this would be something like a SUMIF where you state that the criteria must me Company & Account % Date<=Date
Thnks in advance
using data.table
results
data
EDIT update on OP's extra requirement in the comments