title: remove rows from data frame whose column values don't match another data frame's column values - R
body: <p>So I have two data frames of different dimensions.</p>
  
  <p>The first one, x, is about 10,000 rows and long looks like:</p>
  
  <pre><code>Year    ID    Number
  2008.1  38573 1
  2008.2  24395 3
  </code></pre>
  
  <p>(a lot of data in between)</p>
  
  <pre><code>2008.4  532   4
  </code></pre>
  
  <p>The second one, x2, is about 80,000 rows long and looks like:</p>
  
  <pre><code>Year    ID     Number
  2008.1  38573  2
  2008.2  24395  3
  </code></pre>
  
  <p>(a lot of data in between)</p>
  
  <pre><code>2008.4  532    4
  </code></pre>
  
  <p>Basically, I want to remove the rows in the second data that satisfy the following condition: that the Year, ID and Number values in the row don't match any rows of the first data frame. So in the above example, I'd remove row 1 from the second data frame, because the Number doesn't match.</p>
  
  <p>I've tried:</p>
  
  <pre><code>x2new &lt;- x2[(x2$ID == x$ID &amp;&amp; x2$Year==x$Year &amp;&amp; x2$Number == x$Number),]
  </code></pre>
  
  <p>But it doesn't work because the lengths of the two data frames are different.</p>
  
  <p>I've tried doing a double for loop to remove rows that don't have all 3 conditions, but R simply can't do that many iterations.</p>
  
  <p>Please help! Thanks.</p>