title: Filtering for multiple strings within the same column in r
body: <p>My large data set (Groceries) has a column in it containing character data (Fruits) all of which is lower case and all of which contains no punctuation. </p>
  
  <p>It looks a bit like this:</p>
  
  <pre><code># Groceries Data Frame
  Id    Groceries$Fruits
  1     apple orange banana lemon grapefruit
  2     grapes tomato passion fruit
  3     strawberry orange kiwi
  4     lemon orange passion fruit grapefruit lime
  5     lemon orange passion fruit grapefruit lime peach
    ...
  </code></pre>
  
  <p>I'm trying to select all the rows (of which there are 3,320) from the Fruits column that contain 5 specific fruits (orange, lime, lemon, grapefruit &amp; passion fruit). Initially I'm only interested in the rows that contain all 5 of these fruits and no additional Fruits. Thus, the only row out of these 5 that should be filtered/subsetted would be row 4. The fruits do not have to be in any particular order.</p>
  
  <p>The data is actually answers to a test, so eventually I'm interested in determining who got 0/5 fruits, who got 1/5, 2/5 and so on...</p>
  
  <p>I've tried 2 methods so far, both to no avail. 
  Firstly I tried using grep(), but no rows were stored in the resulting data frame.</p>
  
  <pre><code># 1st attempt with grep()
  Correct fruits &lt;- Groceries[grep("orange, lemon, lime, passion fruit, 
  grapefruit", Groceries$Fruits), ]
  </code></pre>
  
  <p>And then I tried using filter(), but the selected rows don't contain just the 5 Fruits I'm seeking out, it selects all rows that contain any of the 5 fruits.</p>
  
  <pre><code># 2nd attempt with filter
  library(dplyr)
  library(stringr)
  CorrectFruits &lt;- c("lemon", "orange", "passion fruit", "grapefruit", 
  "lime")
  
  filter &lt;- Groceries %&gt;%
    select(Id, Fruits) %&gt;%
    filter(str_detect(tolower(Fruits), pattern = CorrectFruits))
  </code></pre>
  
  <p>The result I'm after initially is a new DF containing all the columns in the Groceries table, but only the rows of those people who got all 5 of the chosen fruits correct.</p>
  
  <p>Next, it would be cool to select the opposite; everyone who didn't get all 5 correct.</p>
  
  <p>Finally, I'd love to be able to subset those who got a specific proportion correct. I.e. row 1 got 3 correct, row 2 only got 1 correct and row 3 only got 1 correct.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Here's an example of what some of the columns look like:</p>
  
  <pre><code># Groceries
  Id   Age      Nationality    Colour question   Fruits question
  1    26-35    Canadian       Red               apple orange banana lemon grapefruit
  2    26-35    US             Blue              grapes tomato passion fruit
  3    46-55    Canadian       Red               strawberry orange kiwi
  4    55+      US             Red               lemon orange passion fruit grapefruit lime
  5    36-45    British        Green             lemon orange passion fruit grapefruit lime peach
  </code></pre>