title: how to select specific part of the grouped data in R?
body: <p>After grouping the data by ID, I want to get the ones that contain at least 2 values after F2 in the Visit column.</p>
  <p>Let me show it in the example below. &quot;dt&quot; is my input and &quot;ot&quot; is my output. I create &quot;ot&quot;, 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.</p>
  <p>Thanks for your help.</p>
  <pre><code>dt&lt;-data.frame(ID=c(100,100,100,100,100,100,100,
                      101,101,101,101,101,101,
                      102,102,102,102),
                 Visit=c(&quot;Bsl&quot;, &quot;F1&quot;, &quot;F2&quot;, &quot;F3&quot;, &quot;F4&quot;, &quot;F5&quot;, &quot;F6&quot;,
                         &quot;Bsl&quot;, &quot;F1&quot;, &quot;F2&quot;, &quot;F3&quot;, &quot;F4&quot;, &quot;F5&quot;,
                         &quot;Bsl&quot;, &quot;F1&quot;, &quot;F2&quot;, &quot;F3&quot;),
                 X1=c(21,22,28,26,33,34,37, 
                      44,43,48,50,52,57,
                      69,67,66, 70))
  
  ot&lt;-data.frame(ID=c(100,100,100,100,100,100,100,
                      101,101,101,101,101,101),
                 Visit=c(&quot;Bsl&quot;, &quot;F1&quot;, &quot;F2&quot;, &quot;F3&quot;, &quot;F4&quot;, &quot;F5&quot;, &quot;F6&quot;,
                         &quot;Bsl&quot;, &quot;F1&quot;, &quot;F2&quot;, &quot;F3&quot;, &quot;F4&quot;, &quot;F5&quot;),
                 X1=c(21,22,28,26,33,34,37, 
                      44,43,48,50,52,57))
  
  </code></pre>