title: How to adjust multiple label vectors on the same categorical values?
body: <p>I have two data frames (<code>df1</code>, <code>df2</code>) with the same columns (<code>catVar</code>, <code>label</code>), resulting from different sources. I would like to join these two dataframes using the <code>catVar</code> variable and create a new <code>label</code> column based on the information in <code>df1$label</code> and <code>df2$label</code>.</p>
  <p>Is there any existing function available within the tidyverse environment?</p>
  <pre><code>library(tidyverse)
  
  df1 &lt;- data.frame(catVar = c(&quot;A&quot;, &quot;B&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;, &quot;I&quot;),
                    label = c(1, 1, 2, 2, 3, 3, 4, 4))
  
  df2 &lt;- data.frame(catVar = c(&quot;A&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;, &quot;I&quot;, &quot;J&quot;),
                    label = c(1, 1, 3, 3, 2, 2, 5, 5, 4))
  
  df1 %&gt;% full_join(df2, by = c(&quot;catVar&quot;), suffix = c(&quot;_df1&quot;, &quot;_df2&quot;))
  # 
  #    catVar label_df1 label_df2
  # 1       A         1         1
  # 2       B         1        NA
  # 3       D         2         3
  # 4       E         2         3
  # 5       F         3         2
  # 6       G         3         2
  # 7       H         4         5
  # 8       I         4         5
  # 9       C        NA         1
  # 10      J        NA         4
  </code></pre>
  <p>Expected output: the values in <code>catVar</code> tend to have similar labels but different values. For example, D, E tend to have the same value, but they have <code>2</code> in <code>df1$label</code> and <code>3</code> in <code>df2$label</code>. The label value itself is not important as long as all the common elements have the same label i.e., it does not matter <code>D</code>, <code>E</code> have <code>2</code> or <code>3</code> as long as both have the same label in the output.</p>
  <p>Sometimes, they are present only in one data frame (J only in <code>df2</code>).</p>
  <pre><code>#    catVar label_df1 label_df2 label
  # 1       A         1         1     1
  # 2       B         1        NA     1
  # 3       D         2         3     2
  # 4       E         2         3     2
  # 5       F         3         2     3
  # 6       G         3         2     3
  # 7       H         4         5     4
  # 8       I         4         5     4
  # 9       C        NA         1     1
  # 10      J        NA         4     5
  </code></pre>