title: R: Filtering on the basis of row data
body: <p>I have a data frame like this-</p>
  <pre><code>df &lt;- structure(list(Category = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;, 
  &quot;D&quot;, &quot;D&quot;), Subcategory = c(&quot;A_1&quot;, &quot;A_2&quot;, &quot;A_3&quot;, &quot;B_1&quot;, &quot;B_2&quot;, 
  &quot;C_1&quot;, &quot;C_2&quot;, &quot;D_3&quot;, &quot;D_4&quot;), Option = c(&quot;Q1&quot;, &quot;Q2&quot;, &quot;Q3&quot;, &quot;Q4&quot;, 
  &quot;Q5&quot;, &quot;Q6&quot;, &quot;Q7&quot;, &quot;Q8&quot;, &quot;Q9&quot;)), row.names = c(NA, -9L), class = c(&quot;tbl_df&quot;, 
  &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p>Results of <code>df</code> :</p>
  <pre class="lang-none prettyprint-override"><code>  Category Subcategory Option
  1        A         A_1     Q1
  2        A         A_2     Q2
  3        A         A_3     Q3
  4        B         B_1     Q4
  5        B         B_2     Q5
  6        C         C_1     Q6
  7        C         C_2     Q7
  8        D         D_3     Q8
  9        D         D_4     Q9
  </code></pre>
  <p>I want the output as such the data gets filtered based on <code>Category</code> basis . Like when I select <code>&quot;A&quot;</code>, the output should be:</p>
  <p>A_1
  A_2,
  A_3.</p>
  <p>and when I select <code>A_1</code>, I get <code>Q1</code>.</p>
  <p>and subsequently for all categories.</p>