title: Creating new variable in dataframe based on matching values from other dataframe
body: <p>I have two dataframes, df1 and df2, of which two columns have partly matching values, however in completely different order; also, the values are unique in df2 but may be repeated in df1. 
  What I'd like to do is transfer into df1, not the matching values, but values associated with them in another variable in df2; for one value in df1, "G", I do not want the associated value to be transferred but rather just NA.</p>
  
  <p>Consider df1 and df2:</p>
  
  <pre><code>df1 &lt;- data.frame(
    x = c("A", NA, "L", "G", "C", "F", NA, "J", "G", "K")
  )
  
  df2 &lt;- data.frame(
    a = LETTERS[1:10],
    b = 1:10   # these are the values to be transferred into df1$z
  )
  
  df1$z &lt;- ifelse(df1$x=="G", NA, ifelse(df1$x %in% df2$a, df2$b[df2$a %in% df1$x], NA))
  </code></pre>
  
  <p>The values to be transferred from df2 into df1 are in df2$b. I've tried the above ifelse() string but the resulting values in df1$z are only partly correct. Where's the mistake?</p>