title: Looking for a dplyr function to apply a filter conditionally
body: <p>I have a data frame of various hematology values and their collection times. Those values should only be collected at specific times, but occasionally an extra one is added. I want to remove any instances where a value was collected outside the scheduled time.</p>
  
  <p>To illustrate the issue, here's some code to create a very simplified version of the data frame I'm working with (plus some example schedules):</p>
  
  <pre><code>example &lt;- tibble("Parameter" = c(rep("hgb", 3), rep("bili", 3), rep("LDH", 3)), 
                    "Collection" = c(1, 3, 4, 1, 5, 6, 0, 4, 8))
  
  hgb_sampling &lt;- c(1, 4)
  bili_sampling &lt;- c(1, 5)
  ldh_sampling &lt;- c(0, 4)
  
  </code></pre>
  
  <p>So, I need an way to conditionally apply a filter based on the value in the Parameter column. The solution needs to fit into a dyplr pipeline and yield something like this:</p>
  
  <pre><code>filtered &lt;- tibble("Parameter" = c(rep("hemoglobin", 2), rep("bilirubin", 2), rep("LDH", 2)), 
                    "Collection" = c(1, 4, 1, 5, 0, 4))
  </code></pre>
  
  <p>I've tried a couple things (they all amount to something like the below) but the use of "Parameter" trips things up:</p>
  
  <pre><code>df &lt;- example %&gt;%
    {if (Parameter == "hgb") filter(., Collection %in% hgb_sampling)} 
  </code></pre>
  
  <p>Any suggestions?</p>