After grouping the data by ID, I want to get the ones that contain at least 2 values after F2 in the Visit column.
Let me show it in the example below. "dt" is my input and "ot" is my output. I create "ot", because ID 102 has only F3 after F2, aka this ID doesnot have at least 2 visits after F2. If it had visits F3, F4, I'd select ID 102 as well.
Thanks for your help.
dt<-data.frame(ID=c(100,100,100,100,100,100,100,
101,101,101,101,101,101,
102,102,102,102),
Visit=c("Bsl", "F1", "F2", "F3", "F4", "F5", "F6",
"Bsl", "F1", "F2", "F3", "F4", "F5",
"Bsl", "F1", "F2", "F3"),
X1=c(21,22,28,26,33,34,37,
44,43,48,50,52,57,
69,67,66, 70))
ot<-data.frame(ID=c(100,100,100,100,100,100,100,
101,101,101,101,101,101),
Visit=c("Bsl", "F1", "F2", "F3", "F4", "F5", "F6",
"Bsl", "F1", "F2", "F3", "F4", "F5"),
X1=c(21,22,28,26,33,34,37,
44,43,48,50,52,57))