title: efficiently data subset based on data frame columns matching in R
body: <p>I have two data frames, say df1 and df2. Now I want to subset df2 based on the matching of multiple columns between df1 and df2.</p>
  
  <p>e.g</p>
  
  <pre><code>df1                                   
     A   B  #column names, rows in df1 are unique, A1,B1 etc are characters                  
     A1  B1                                
     A2  B2 
     ......                               
  
  
  
    df2  
    C     D     E   F    G  
    A1    B1    E1  F1   G1
    A2    B2    E2  .......  
    A1    B2    E3  .......  
    A1    B1    E4  .......  
    A2    B1    E5  .......  
  </code></pre>
  
  <p>Here I want to match columns A and B in df1 to columns C and D in df2,and construct a new data frame df3, where each row of df3 store the row index of df2 where matching happens.
  For my example, it should be</p>
  
  <pre><code>df3
  c(1,4)
  c(2)
  </code></pre>
  
  <p>Originally I am thinking of paste characters and do string comparison to do the matching, but I suspect this is not the efficient way to do this, any better idea?</p>