I have troubles with the following problem. I need to keep track of the maximum value of crp
and gluc
for each ID
in the 3 hours before and after each measurement in a series. I tried different solutions over the last few months and was not able to solve this. I have a dataset like the one below:
ID crp gluc hour
1 5 300 0.3
1 2 NA 0.9
1 NA 89 1.2
1 9 NA 4
1 NA 100 7.1
2 0 NA 0.3
2 NA 50 1
2 NA 70 2.2
2 1 80 5
The result should be:
ID crp gluc hours maxCrp MaxGluc
1 5 300 0.3 5 300
1 2 NA 0.9 5 300
1 NA 89 1.2 9 300
1 9 NA 4 9 89
1 NA 100 7.1 NA 100
2 0 NA 0.3 0 70
2 NA 50 1 0 70
2 NA 70 2.2 1 80
2 1 80 5 1 80
Thank you in advance, Erik