title: Add a filter and a filter as a consequence in R
body: <p>I have this dataset:</p>
  <pre><code>df_example &lt;- data.frame(id = c(&quot;A1&quot;,&quot;A2&quot;,&quot;A3&quot;,&quot;A4&quot;,&quot;A5&quot;,&quot;A6&quot;,&quot;A7&quot;),
                           amount = c(12,13,15,12,12,15,18),
                           flag = c(0,0,0,1,0,0,0),
                           upg = c(NA,NA,&quot;A4&quot;,NA,&quot;A7&quot;,NA,NA),
                           stringsAsFactors = FALSE)
  </code></pre>
  <p>I want to filter the dataset firstly if the <code>id</code> is contained in column <code>upg</code>. After that, filter out only where column <code>flag</code> is 1 (related to <code>id</code>)</p>
  <p>Expected output should be:</p>
  <pre><code>id    amount    flag    upg
  A4    12        1       NA
  </code></pre>
  <p>I tried this:</p>
  <pre><code>df_example[df_example$id %in% df_example$upg &amp;&amp; df_example$flag == 1,]
  </code></pre>
  <p>But it returns an empty result.</p>
  <p>Please, an answer in base R would be highly appreciated.</p>