The data is in the following format, where i have to group_by it using Date. For convenience i have shown it as numbers.
Msg <- c("Errors","Errors", "Start","Stop","Start","Stop","Errors","Errors","Start","Stop",
"Stop" ,"Start","Errors","Start","Stop","Start" ,"Stop" ,
"Errors", "Start","Errors","Stop", "Start", "LostControl","LostControl", "Errors",
"Failed", "Stop", "Start","Failed","Stop","Stop","Start","Stop","Start","Error","Start",
"Failed", "Stop")
Date <- c(11,11,11,11,11,11,11,12,12,12,12,12,12,14,14,14,14, 19,19,19,19,
20,20,20,20,20,20,21,21,21,21,22,22,22,22,22,22,22)
data<- data.frame(Msg,Date)
I need to count the number of Failed in each START-STOP cycle, summarized by Date.
The data has three types of Messages.
Errors and Failed are two type of Failure msgs, whereas LostControl is not a Failure.
The condition is that a Failed msg shall not be preceded by a LostControl msg in that START-STOP cycle. If it is preceded by Errors only, it is Failure.
Also, If only a "Errors" msg is found, it is also not counted as a Failure.
Edit: In the Msg vector, a START_STOP cycle is from extreme start to extreme stop iff two Starts or stops are found. If a START does not have a STOP follwing, it is ignored.
Edit one row added as - (Msg =Stop, Date=20)