I wonder if there is an easy way to calculate the duration. I have a dataset where the a parameter, called m
, varies between the values -1
and 1
during time. I want to calculate:
- The total duration (time in hours) of cases where
m=-1
andm=1
respectively How long is each period of cases where
m=-1
andm=1
respectively ism<-c(1,1,1,1,-1,-1,-1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1)
Time <- seq.POSIXt(as.POSIXct(Sys.Date()), as.POSIXct(Sys.Date()+1), by = "1 hour")