I have a dataframe with a vector in the follwing format I want to keep all rows, within the "START" and "STOP" values in the column val (including them), and remove rows that is not inside start-stop
id = str_c("x",1:20)
val = c(rep("NO1", 3), "START", rep("yes1", 3), "STOP",
"NO2", "START", rep("yes2", 3), "STOP", rep("NO3",6))
data = data.frame(id,val)
My expected output is
data = data.frame(id = c(str_c("x", 4:8), str_c("x", 10:14)),
val = c("START", rep("yes1", 3), "STOP",
"START", rep("yes2", 3), "STOP"))