title: How to find values shared between groups in a data frame?
body: <p>I have a tidy data.frame with two columns: <code>exp</code> and <code>val</code>. I want to find which values of <code>val</code> are shared among all different experiments.</p>
  
  <pre><code>df &lt;- data.frame(exp = c('A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C'),
                   val = c(10, 20, 15, 10, 10, 15, 99, 2, 15, 20, 10, 4))
  df
  
     exp val
  1    A  10
  2    A  20
  3    A  15
  4    A  10
  5    B  10
  6    B  15
  7    B  99
  8    B   2
  9    C  15
  10   C  20
  11   C  10
  12   C   4
  </code></pre>
  
  <p>Expected result could be either a vector of values:</p>
  
  <pre><code>10, 15
  </code></pre>
  
  <p>or a column on the data frame telling if that value is shared:</p>
  
  <pre><code>   exp     val shared
     &lt;fct&gt; &lt;dbl&gt; &lt;lgl&gt; 
   1 A        10 TRUE  
   2 A        20 FALSE 
   3 A        15 TRUE  
   4 A        10 TRUE  
   5 B        10 TRUE  
   6 B        15 TRUE  
   7 B        99 FALSE 
   8 B         2 FALSE 
   9 C        15 TRUE  
  10 C        20 FALSE 
  11 C        10 TRUE  
  12 C         4 FALSE 
  </code></pre>
  
  <p>I was able to find an answer (see the self-answer below) but this seems like a common enough question that there <strong>must</strong> be a better way than the really hacky solution I cam up with.</p>
  
  <p>I tried to solve this problem in <code>dplyr</code> since that's what I'm familiar with, but I'm interested in any kind of solution.</p>