title: Using the %in% function for multiple columns to
body: <p>I am trying to use the %in% function to match the observations of one of my datasets to the observations of another dataset. Essentially, I would like to make two new datasets, one that contains the observations of the second dataset, and another which contains all other observations. Here is an example dataset:</p>
  <pre><code>Df
  Last.Name   First.Name        Group
  Williams      Bob                A
  Williams      Dan                C
  Miller        Bob                A
  Smith         Dan                C
  Williams      Rick               A
  Smart         Jeff               C
  Miller        Bob                A
  Smith         Dan                C
  Jones         Bob                A
  Williams      Buddy              C
  Miller        Bob                A
  Hends         Dan                C
  Williams      Rick               A
  Smart         Jeff               C
  Millers       Bob                A
  Smith         Danny              C
  </code></pre>
  <p>Here is a dataset that I am trying to match the observations:</p>
  <pre><code>dfMatch
  LastName   FirstName   
  Williams      Bob          
  Williams      Buddy                     
  Miller        Bob                  
  Smith         Dan                  
  Williams      Rick                  
  Smart         Jeff                  
  Miller        Bob                 
  Smith         Dan                 
  </code></pre>
  <p>I tried various versions of the following code:</p>
  <pre><code>newdf&lt;-Df[ Df$Last.Name %in% DfMatch$LastName &amp; Df$First.Name %in% DfMatch$FirstName,]
  </code></pre>
  <p>and</p>
  <pre><code> newdf&lt;-Df[ which(Df$Last.Name %in% DfMatch$LastName &amp; Df$First.Name %in% DfMatch$FirstName),]
  </code></pre>
  <p>To get this new dataset:</p>
  <pre><code>newDF
  Last.Name   First.Name          Group
  Williams      Bob                  A
  Miller        Bob                  A
  Smith         Dan                  C
  Williams      Rick                 A
  Smart         Jeff                 C
  Miller        Bob                  A
  Smith         Dan                  C
  Williams      Buddy                C
  </code></pre>
  <p>However, this does not work.</p>
  <p>I would also like to use similar code to build a dataset which includes all observations not listed in the dfMatch set, such as:</p>
  <pre><code>DfNoMatch
  Last.Name   First.Name          Group
  Williams      Dan                  C
  Jones         Bob                  A
  Miller        Bob                  A
  Hends         Dan                  C
  Williams      Rick                 A
  Smart         Jeff                 C
  Millers       Bob                  A
  Smith         Danny                C
  </code></pre>
  <p>By using code similar to:</p>
  <pre><code> DfNoMatch&lt;-Df[ !Df$Last.Name %in% DfMatch$LastName &amp; Df$First.Name %in% DfMatch$FirstName,]
  </code></pre>
  <p>and</p>
  <pre><code> DfNoMatch&lt;-Df[! which(Df$Last.Name %in% DfMatch$LastName &amp; Df$First.Name %in% DfMatch$FirstName),]
  </code></pre>
  <p>Thank you in advance and any help is greatly appreciated!</p>