title: How to subset based on multiple variables in one column
body: <p>Good afternoon,</p>
  <p>I am trying to filter a data frame that includes 94 different items and how much they were sold in different hours, by the top 15 items sold overall, from the data below:</p>
  <pre><code>structure(list(Time = c(&quot;07&quot;, &quot;07&quot;, &quot;07&quot;, &quot;07&quot;, &quot;07&quot;, &quot;08&quot;), 
  Item = c(&quot;Bread&quot;, &quot;Coffee&quot;, &quot;Medialuna&quot;, &quot;Pastry&quot;, &quot;Toast&quot;, 
  &quot;Afternoon with the baker&quot;), Transactions = c(2L, 13L, 6L, 
  2L, 1L, 3L)), row.names = c(NA, -6L), groups = structure(list(
  Time = c(&quot;07&quot;, &quot;08&quot;), .rows = structure(list(1:5, 6L), ptype = integer(0), class = c(&quot;vctrs_list_of&quot;, 
  &quot;vctrs_vctr&quot;, &quot;list&quot;))), row.names = 1:2, class = c(&quot;tbl_df&quot;, 
  &quot;tbl&quot;, &quot;data.frame&quot;), .drop = TRUE), class = c(&quot;grouped_df&quot;, 
  &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p>I already know the 15 most popular items by name (&quot;Coffee&quot;, &quot;Tea&quot;, &quot;Bread&quot;, etc.), and I have tried to subset the data frame using the code below:</p>
  <pre><code>SalesPerTimePerItem &lt;- subset(SalesPerTimePerItem,
                            Item == c(&quot;Coffee&quot;,
                                      &quot;Tea&quot;,
                                      &quot;Bread&quot;,
                                      &quot;Cake&quot;,
                                      &quot;Pastry&quot;,
                                      &quot;Sandwich&quot;,
                                      &quot;Medialuna&quot;,
                                      &quot;Hot chocolate&quot;,
                                      &quot;Cookies&quot;,
                                      &quot;Brownie&quot;,
                                      &quot;Farm House&quot;,
                                      &quot;Muffin&quot;,
                                      &quot;Alfajores&quot;,
                                      &quot;Juice&quot;,
                                      &quot;Soup&quot;))
  </code></pre>
  <p>But I have received this error:</p>
  <pre><code>In Item == c(&quot;Coffee&quot;, &quot;Tea&quot;, &quot;Bread&quot;, &quot;Cake&quot;, &quot;Pastry&quot;, &quot;Sandwich&quot;,  :
    longer object length is not a multiple of shorter object length
  </code></pre>
  <p>I have also tried another method below:</p>
  <pre><code>SalesPTPI &lt;- SalesPTPI[SalesPTPI$Item %in% c(&quot;Coffee&quot;,
                                           &quot;Tea&quot;,
                                           &quot;Bread&quot;,
                                           &quot;Cake&quot;,
                                           &quot;Pastry&quot;,
                                           &quot;Sandwich&quot;,
                                           &quot;Medialuna&quot;,
                                           &quot;Hot chocolate&quot;,
                                           &quot;Cookies&quot;,
                                           &quot;Brownie&quot;,
                                           &quot;Farm House&quot;,
                                           &quot;Muffin&quot;,
                                           &quot;Alfajores&quot;,
                                           &quot;Juice&quot;,
                                           &quot;Soup&quot;)]
  </code></pre>
  <p>But got the error:</p>
  <pre><code>Error: Must subset columns with a valid subscript vector.
  i Logical subscripts must match the size of the indexed input.
  x Input has size 3 but subscript `i` has size 631.
  </code></pre>
  <p>My aim, with this data, is to create a barplot like the one I have linked below:</p>
  <p><a href="https://i.stack.imgur.com/T9DR8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T9DR8.png" alt="enter image description here" /></a></p>
  <p>but with different objects:</p>
  <pre><code>(x = Time, y = Transactions, fill = Item)
  </code></pre>
  <p>How I can filter out only the 'Coffee', etc., responses from the data frame included at the top?</p>