How do I convert this done in Data Tables into a R data frame operation:
DT[, group_id := rleid(((v1 <95 | v2 <95))) ][]
#group by group_id, only on rows where v1 or v2 > 110
z<-DT[((v1 <95 |v2<95)), ][, .(start = min(timestamp),
end = max(timestamp),
duration = as.numeric(max(timestamp)-min(timestamp),units='mins')),
by = .(group_id)][,group_id :=
NULL]
Sample data :
DT <- fread("timestamp v1 v2
14-05-2019T04:28 112.2 111.0
14-05-2019T04:30 112.2 110.9
14-05-2019T04:39 101.4 101.8
14-05-2019T04:40 108.0 108.8
14-05-2019T04:45 101.1 101.5
14-05-2019T04:46 100.8 101.2
14-05-2019T05:32 111.6 111.5
14-05-2019T05:36 111.5 111.5
14-05-2019T05:39 111.5 111.5
14-05-2019T05:41 111.5 111.5
14-05-2019T05:46 111.5 111.4
14-05-2019T05:46 111.5 111.3
14-05-2019T05:47 111.5 111.3
14-05-2019T05:51 111.2 111.2
14-05-2019T05:56 111.2 111.2
14-05-2019T05:57 111.2 111.2")
I am trying to convert this into a more friendly code using dataframe, rather than using data table. How can I achieve it