title: Deduplicating/collapsing records in an R dataframe
body: <p>I have a dataset that is comprised of various individuals, where each individual has a unique id. Each individual can appear multiple times in the dataset, but it's my understanding that besides differing in one or two variables (there are about 80 for each individual) the values should be the same for each entry for the same user id in the dataset. </p>
  
  <p>I want to try to collapse the data if I can. My main obstacle is certain null values that I need to back populate. I'm looking for a function that can accomplish deduplication looking something like this:</p>
  
  <pre><code># Build sample dataset
  df1 = data.frame(id=rep(1:6,2)                 
                  ,classA=rep(c('a','b'),6)
                  ,classB=rep(c(1001:1006),2)
                  )
  df1= df1[order(df1$id),]
  df1$classC=c('a',NA,'b',NA,NA,NA,'e','d', NA, 'f', NA, NA)
  df1[10,"classB"]=NA
  df1=df1[df1$id!=6,]
  
  #sample dataset
  &gt; df1
     id classA classB classC
  1   1      a   1001      a
  7   1      a   1001   &lt;NA&gt;
  2   2      b   1002      b
  8   2      b   1002   &lt;NA&gt;
  3   3      a   1003   &lt;NA&gt;
  9   3      a   1003   &lt;NA&gt;
  4   4      b   1004      e
  10  4      b   1004      d
  5   5      a   1005   &lt;NA&gt;
  11  5      a     NA      f        
  
  # what I'm looking for
  &gt; deduplicate(df1, on='id')
    id classA classB classC
  1  1      a   1001      a
  2  2      b   1002      b
  3  3      a   1003   &lt;NA&gt;
  4  4      b   1004      d
  5  4      b   1004      e
  6  5      a   1005      f     
  </code></pre>