Using data.table
Assuming your source data is called dt
and was setDT()
, then you could do:
df <- rbind(
dt[status == "end_of_day", .(QT_REC = sum(QT_REC, na.rm = TRUE)),
by = .(CASHPOINT_ID, DT, status)],
dt[status != "end_of_day"]
)[order(DT)]
print(df)
CASHPOINT_ID DT status QT_REC
1: N053360330 2016-01-01 end_of_day 7
2: N053360330 2016-01-02 before 9
3: N053360330 2016-01-02 before NA
4: N053360330 2016-01-03 end_of_day 16
source
share