I have an irregular time series, and i'm trying to account with R a rolling sum on 3 month window for each operation associated to an ID.
data are structured as follow
ID Operation date value
A 1 01/01/2017 0
A 2 01/02/2017 1
A 3 01/06/2017 1
A 4 01/09/2017 0
B 1 01/03/2017 0
B 2 01/05/2017 1
B 3 01/09/2017 0
B 4 01/10/2017 1
i'm looking for this output
ID Operation date value cumsum
A 1 01/01/2017 0 0
A 2 01/02/2017 1 1
A 3 01/06/2017 1 1
A 4 01/09/2017 0 1
B 1 01/03/2017 0 0
B 2 01/05/2017 1 1
B 3 01/09/2017 1 1
B 4 01/10/2017 1 2
now i'm using this script
DB<-DB[with(DB,order(ID,date)),]
DB<-DB %>% group_by(ID) %>% mutate(cumsum = cumsum(value))
but it sum value for all past operation. how can i introduce the 3 month rolling sum?