I have a xts-timeseries temperature data in 5 min resolution.
head(dataset)
Time Temp
2016-04-26 10:00:00 6.877
2016-04-26 10:05:00 6.877
2016-04-26 10:10:00 6.978
2016-04-26 10:15:00 6.978
2016-04-26 10:20:00 6.978
- I want to calculate the longest duration the temperature exceeds a certain threshold. (let's say 20 °C)
- I want to calculate all the periods with their duration the temperature exceeds a certain threshold.
I create a data.frame from my xts-data:
df=data.frame(Time=index(dataset),coredata(dataset)) head(df) Time Temp 1 2016-04-26 10:00:00 6.877 2 2016-04-26 10:05:00 6.877 3 2016-04-26 10:10:00 6.978 4 2016-04-26 10:15:00 6.978 5 2016-04-26 10:20:00 6.978 6 2016-04-26 10:25:00 7.079
then I create a subset with only the data that exceeds the threshold:
sub=(subset(x=df,subset = df$Temp>20)) head(sub) Time Temp 7514 2016-05-22 12:05:00 20.043 7515 2016-05-22 12:10:00 20.234 7516 2016-05-22 12:15:00 20.329 7517 2016-05-22 12:20:00 20.424 7518 2016-05-22 12:25:00 20.615 7519 2016-05-22 12:30:00 20.805
But now im having trouble to calculate the duration of the event the temperature exceeds the threshold. I dont know how to identify a connected period and calculate their duration?
I would be happy if you have a solution for this question (it's my first thread so please excuse minor mistakes) If you need more information on my data, feel free to ask.