I have this dataframe in R
raw_payment_id from_bank_account amount posted_at
<int> <chr> <dbl> <date>
1 620691 SK660900000000062087 20.0 2018-02-25
2 618433 SK660900000000062087 10.0 2018-02-27
3 623157 SK660900000000062087 10.0 2018-03-02
4 628236 SK300900000000506871 812. 2018-03-06
5 627899 SK300900000000506871 812. 2018-03-07
6 628966 SK660900000000062087 10.0 2018-03-09
My goal is to find if payment from same account and at same amount was posted within 3 days. And if yes, mark both payments with 1. So result would be.
raw_payment_id from_bank_account amount posted_at test
<int> <chr> <dbl> <date> <int>
1 620691 SK660900000000062087 20.0 2018-02-25 0
2 618433 SK660900000000062087 10.0 2018-02-27 1
3 623157 SK660900000000062087 10.0 2018-03-02 1
4 628236 SK300900000000506871 812. 2018-03-06 1
5 627899 SK300900000000506871 812. 2018-03-07 1
6 628966 SK660900000000062087 10.0 2018-03-09 0
I can´t find a way how to do that, my tryings with lag/leads fails on fact that there could be only one payment from bank account.