title: How can I get rows with specific conditions in r
body: <p>Say that I have a <code>df</code>.</p>
  <p>I want to get the <code>id</code> with two conditions at the same time:</p>
  <ol>
  <li><p>the <code>id</code>'s <code>code</code> should contaions a capital <code>I</code>, regardless of the number that follows it. For example <code>I11</code>, <code>I31</code>...</p>
  </li>
  <li><p>the <code>id</code>'s <code>code</code> should contaions specific <code>code</code>: <code>E12</code>.</p>
  </li>
  </ol>
  <p>On the example below, the filtered <code>id</code> should be <code>id = 1</code> and <code>id = 2</code>. Because they all  contain <code>I</code> and <code>E12</code>.</p>
  <p>Same <code>id</code> in the example means in the same group.</p>
  <pre><code>structure(list(id = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 
  3, 3, 3, 4, 4, 4, 4, 4, 4), diag = c(&quot;main&quot;, &quot;other&quot;, &quot;main&quot;, 
  &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, 
  &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, &quot;other&quot;, &quot;main&quot;, 
  &quot;other&quot;, &quot;main&quot;, &quot;other&quot;), code = c(&quot;I11&quot;, &quot;E12&quot;, &quot;I11&quot;, &quot;Q34&quot;, 
  &quot;I31&quot;, &quot;C33&quot;, &quot;E12&quot;, &quot;I34&quot;, &quot;E12&quot;, &quot;I45&quot;, &quot;E12&quot;, &quot;Z11&quot;, &quot;E13&quot;, 
  &quot;Z12&quot;, &quot;E14&quot;, &quot;Z13&quot;, &quot;I25&quot;, &quot;E1&quot;, &quot;I25&quot;, &quot;E2&quot;, &quot;I25&quot;, &quot;E3&quot;)), class = c(&quot;grouped_df&quot;, 
  &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, -22L), groups = structure(list(
      id = c(1, 2, 3, 4), .rows = structure(list(1:6, 7:10, 11:16, 
          17:22), ptype = integer(0), class = c(&quot;vctrs_list_of&quot;, 
      &quot;vctrs_vctr&quot;, &quot;list&quot;))), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ), row.names = c(NA, -4L), .drop = TRUE))
  
  &gt; df
  # A tibble: 22 × 3
  # Groups:   id [4]
        id diag  code 
     &lt;dbl&gt; &lt;chr&gt; &lt;chr&gt;
   1     1 main  I11  
   2     1 other E12  
   3     1 main  I11  
   4     1 other Q34  
   5     1 main  I31  
   6     1 other C33  
   7     2 main  E12  
   8     2 other I34  
   9     2 main  E12  
  10     2 other I45  
  # … with 12 more rows
  </code></pre>