title: Keeping only certain rows of a data frame based on a set of values
body: <p>I have a data frame with an ID column and a few columns for values. I would like to only keep certain rows of the data frame based on whether or not the value of ID at that row matches another set of values (for instance, called "keep").</p>
  
  <p>For simplicity, here is an example:</p>
  
  <pre><code>df &lt;- data.frame(ID = sample(rep(letters, each=3)), value = rnorm(n=26*3))
  keep &lt;- c("a", "d", "r", "x")
  </code></pre>
  
  <p>How can I create a new data frame consisting of rows that only have IDs that match those of keep? I can do this for just one letter by using the <code>which()</code> function, but with multiple letters I get warning messages and incorrect returns. I know I could run a for loop through the data frame and extrapolate that way, but I'm wondering if there is a more elegant and efficient way of going about this. Thanks in advance.</p>