title: dplyr lookup table / pattern matching
body: <p>I was looking for a smart, or "tidier" way, to make use of a lookup table in the tidyverse, but could not find a satisfying solution.</p>
  
  <p>I have a dataset and lookup table:</p>
  
  <pre><code># Sample data
  data &lt;- data.frame(patients = 1:5,
                     treatment = letters[1:5],
                     hospital = c("yyy", "yyy", "zzz", "www", "uuu"),
                     response = rnorm(5))
  
  # Lookup table
  lookup &lt;- tibble(hospital = c("yyy", "uuu"), patients = c(1,5))
  </code></pre>
  
  <p>... where each row in the lookup table is the exact pattern for which I want to filter the first tibble (data).</p>
  
  <p>The wanted result would look like this:</p>
  
  <pre><code># A tibble: 3 x 4
    patients treatment hospital response
       &lt;dbl&gt; &lt;chr&gt;     &lt;chr&gt;       &lt;dbl&gt;
  1     1.00 a         yyy       -0.275 
  2     5.00 e         uuu       -0.0967
  </code></pre>
  
  <p>The easiest solution I came up with is something like this:</p>
  
  <pre><code>as.tibble(dat) %&gt;% 
    filter(paste(hospital, patients) %in% paste(lookup$hospital, lookup$patients))
  </code></pre>
  
  <p>However, this must be something that a lot of people regularly do - is there a cleaner and more convienent way to do this (i.e. for more than two columns in your lookup table)?</p>