title: How to subset a dataframe by factor levels of another in R?
body: <p>I have two daframes (A,B) that both contain exactly the same columns. </p>
  
  <pre><code>A&lt;-data.frame(factor=c("A","B","C"),value=c(1,2,3))
  B&lt;-data.frame(factor=c("A","B","C","D","E"),value=c(7,8,9,4,5))
  </code></pre>
  
  <p>At the end I would like to have a subset of <code>B</code> which only contains the levels of <code>A$factor</code> (A,B,C) and the corresponding values. Any idea on how to do this?
  I looked at the <code>merge()</code> function but could not get it it to work.</p>