title: Define a variable based on variables from different data frames in R
body: <p>I need to define a variable in df1 based on variable in df1 <code>df1$person_id</code> and a variable in df2 <code>df2$gender</code>. The structure is the following</p>
  
  <p><em>I have updated the structure of the data because the previous one was wrong.</em></p>
  
  <pre><code>df1 &lt;- structure(list(person_id = c("15813, 15837, 18118, 16672", "8818, 8132, 18045, 18051, 15916, 10204, 18042, 12455, 18218, 18046, 18050, 18165, 18043, 18052, 18048", "8818, 8132, 18051, 18045, 18042, 10204, 12455, 15916, 18218, 18046, 18050, 18165, 18043, 18052, 18048"), gender = c(NA, NA, NA)), row.names = 12:14, class = "data.frame")
  df2 &lt;- structure(list(id = structure(c(278L, 363L, 156L), .Label = c("10096", "10204", "11094", "11096", "11097", "11098", "11102", "11106", "11109", "11116", "11118", "11121"), class = "factor"), gender = c(1L, 1L, 1L)), row.names = c(NA, 3L), class = "data.frame")
  </code></pre>
  
  <p>The desired output is two columns - <code>df1$person_id</code> and <code>df1$gender</code>. <code>df1$gender</code> may have three options: either all male, or all female, or both.
  Please, could you help me?</p>