根据另一个数据框架在R中按3条条件滚动总和
我有一个DF,我需要根据第一个DF的值在另一个数据框中执行滚动总和
- ,按日期&帐户
- 一天
结束 | 是 | 的 | 余额 |
---|---|---|---|
数据 | 这 | 时 | 要 |
我 | 构建 | 框 | 在 |
| | | |
2021-01-02 | A | A | 12 |
2021-01-02 | A | A | 4 |
2021-01-02 | A | B | 4 |
日期 | 公司 | 帐户 | 价值 |
---|---|---|---|
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-01-01-01-01-01-02 | b | x | ii |
2021-01-01-01-01-01-01-02 | b | y | ii |
在Excel中sumif您指出标准必须我公司&帐户%date< =
提前的日期thnks
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用data.table
结果
data
编辑评论中OP的额外要求
using data.table
results
data
EDIT update on OP's extra requirement in the comments
如果您可以编写代码,这样任何人都可以更轻松地复制它,那就更好了。
例如
,您是否尝试过类似的事情:
It would be better if you could write your code so anyone can reproduce it easier.
For example
Anyway, have you tried something like: