title: Better way to filter a data frame with dplyr using OR?
body: <p>I have a data frame in <strong>R</strong> with columns <code>subject1</code> and <code>subject2</code> (which contain Library of Congress subject headings). I'd like to filter the data frame by testing whether the subjects match an approved list. Say, for example, that I have this data frame. </p>
  
  <pre><code>data &lt;- data.frame(
    subject1 = c("History", "Biology", "Physics", "Digital Humanities"),
    subject2 = c("Chemistry", "Religion", "Chemistry", "Religion")
  )
  </code></pre>
  
  <p>And suppose this is the list of approved subjects.</p>
  
  <pre><code>condition &lt;- c("History", "Religion")
  </code></pre>
  
  <p>What I want to do is filter by either subject1 or subject2:</p>
  
  <pre><code>subset &lt;- filter(data, subject1 %in% condition | subject2 %in% condition)
  </code></pre>
  
  <p>That returns items 1, 2, and 4 from the original data frame, as desired.</p>
  
  <p>Is that the best way to filter by multiple fields using <em>or</em> rather than <em>and</em> logic? It seems like there must be a better, more idiomatic way, but I don't know what it is.</p>
  
  <p>Maybe a more generic way to ask the question is to say, if I combine subject1 and subject2, is there a way of testing if any value in one vector matches any value in another vector. I'd like to write something like:</p>
  
  <pre><code>subset &lt;- filter(data, c(subject1, subject2) %in% condition)
  </code></pre>