# Increase greater than 0.3 within moving 48 hour window in multiple observations

I have a dataset of hospital records and have to check for the individual patient, if 'creatinine' increases >= 0.3 within 48 hours and if it increases >= 0.3, at which time point the increase is witnessed. My problem is, that the 48 hour interval has to move from the beginning of the record to the end, as the increase could happen in every interval.

Example:

``````dat = data.table(
patient_id=c(rep(1,7),rep(2,5)),
measurement=c("1","2","3","4","5","6","7","1","2","3","4","5"),
t=c("2019-01-19 05:00","2019-01-19 14:00","2019-01-20 05:00","2019-01-20 15:00","2019-01-21 03:00","2019-01-22 05:00","2019-01-23 05:00","2019-01-19 05:00","2019-01-19 14:00","2019-01-20 05:00","2019-01-20 15:00","2019-01-21 03:00"),
creatinine=c("0.81","0.90","1.00","1.10","1.20","1.30","1.40","0.81","0.90","1.00","1.10","1.20")
)
``````

So 48 hour-interval #1 would be measurement 1 to 5. And the first increase of creatinine >= 0.3 would be from measurement 1 to measurement 5. But there could also be no increase in interval #1, so I have to recheck in interval #2 (measurement 2 to 6) for the increase and so on.

I was thinking of determining the min and max of each interval and getting the difference of both, that way I can determine, whether there is an increase >= 0.3 in this interval. However, I have no idea, on how to shift the 48 hour interval from the beginning of the record to the finish.

I hope, my question is clear and I would really appreciate any help or suggestions.