title: Match and extract values from columns of two dataframes
body: <p>I want to match the values of two columns in two data frames and add a third column, it's better to see the data frames:</p>
  
  <pre><code>FromA &lt;- c("a", "b", "d")
  ToA &lt;- c("a", "k", "h")
  PAC&lt;- c("red", "blue", "black")
  df1 &lt;- data.frame(FromA, ToA, PAC)
  
  &gt; df1
        FromA ToA PAC
    1     a   a   red
    2     b   k  blue
    3     d   h black
  
  FromB&lt;- c("a", "b", "f") 
  ToB  &lt;- c("a", "k", "h")   
  df2&lt;-   data.frame(FromB, ToB)
  
   &gt; df2
         FromB ToB
       1    a  a
       2    b  k
       3    f  h
  </code></pre>
  
  <p>I want the second data frame to get the value of <code>df1$PAC</code> , if the value of the two first columns match.
  the final result:</p>
  
  <pre><code> &gt; DF2
         FromB ToB  PAC
       1    a  a    red
       2    b  k    blue
       3    f  h    NA
  </code></pre>
  
  <p>So, I used sapply()</p>
  
  <pre><code>  df2$PAC&lt;- sapply(1:nrow(df2), function(i) 
              df1$PAC[df1$FromA==df2$FromB[i] &amp; df1$ToA == df2$ToB[i] ])
  </code></pre>
  
  <p>The function works if the two columns match completely, otherwise, it gives me an error. </p>
  
  <p>Could you help me to understand what I'm missing? I'd appreciate it.</p>