title: Combining rows based on aliases in R
body: <p>I have a data frame that looks like this</p>
  <pre><code>df &lt;- data.frame(
    year = c(2011, 2011, 2010, 2010, 2009, 2010, 2009,2008,2010,2009),
    uid = c(7, 8, 9, 11, 12, 12, 13,14,14,14),
    value1=c(2,3,6,4,3,2,1,4,5,6),
    stringsAsFactors = FALSE
  )
  df
     year uid value1
  1  2011   7      2
  2  2011   8      3
  3  2010   9      6
  4  2010  11      4
  5  2009  12      3
  6  2010  12      2
  7  2009  13      1
  8  2008  14      4
  9  2010  14      5
  10 2009  14      6
  </code></pre>
  <p>I have another dataframe that has aliases for the unique identifiers, like this:</p>
  <pre><code>df2 &lt;- data.frame(
  uidAliases = c(&quot;7,11&quot;, &quot;8,13&quot;, &quot;9,12,14&quot;)
  )
  </code></pre>
  <p>First, I want to replace uid based on the df2$uidAliases and then I want to combine the value1 based on uid, year. Basically, what I need is that if there are additional aliases for an uid, the later ones should get replaced. (I know how to do the 2nd part but I am struggling with matching and replacing the UIDs. Much appreciated!)</p>
  <p>The final output should look like this:</p>
  <pre><code>outputdf &lt;- data.frame(
    year = c(2011, 2011, 2010, 2010, 2009,2009,2008),
    uid = c(7, 8, 9, 7, 9, 8,9),
    value1=c(2,3,13,4,9,1,4),
    stringsAsFactors = FALSE
  ) 
  
  year uid value1
  1 2011   7      2
  2 2011   8      3
  3 2010   9     13
  4 2010   7      4
  5 2009   9      9
  6 2009   8      1
  7 2008   9      4
  </code></pre>