I have a group of data in the format:
ID Minutes Value
xxxx 118 3
xxxx 121 4
xxxx 122 3
yyyy 122 6
xxxx 123 4
yyyy 123 8
... ... ....
Each ID is a patient and each value is, say, blood pressure for that minute. I would like to create a rolling average for the 60 minutes before and 60 minutes after each point. However - as you can see, there are missing minutes (so I cannot merely use row numbers) and I would like to create average for each unique ID (so the average for ID xxxx cannot include values assigned to ID yyyy). It sounds like rollapply or rollingstat might be options, but have had little success trying to piece this together...
Please let me know if further clarity is needed.
data.table
, you could set up a loop. Roughly,for (jtime in 1:N) mean(DF[DF$Minutes > (jtime-60) & DF$Minutes < (jtime + 60),3])
– Sheepshead