title: How to combine duplicate rows of a particular column in a data frame in R
body: <p>Given a dataframe in R such as the following</p>
  
  <pre><code>  gen  avg_ep   avgin avg_out avg_gape avg_buc      var_ep      var_in
  1   0 117.189 6.09058 16.8925  14.3930 20.2136 0.000600300 0.000646235
  2   1 117.188 6.09151 16.8900  14.3880 20.2048 0.000607196 0.000619780
  3   2 117.189 6.09269 16.8905  14.3860 20.2033 0.000654027 0.000745787
  4   3 117.192 6.09648 16.8920  14.3875 20.2068 0.000625242 0.000767313
  5   4 117.193 6.09795 16.8910  14.3854 20.2036 0.000680661 0.000943054
  6   5 117.197 6.10452 16.8949  14.3887 20.2091 0.000833197 0.001068240
  7   2 1.197 2 474.00  131.1 210.2091 101.000833197 01.068240
  </code></pre>
  
  <p>I want to transform the dataframe by taking rows with gen values that already exist and combining them with the duplicate row, assigning the mean of their other values to the other columns. That is kind of a mouth full that is best cleared up by an example.</p>
  
  <p>Using the previous dataframe, you can see that the last row ( row 7) has a gen value of 2. I would like that row to combine with the other row with a gen value of 3 (row 3), and then would like the column values for row 3 ( avg_ep, avgin etc)to become means of the two. For example, the avg_ep of row 3 should become (1.197 + 117.189)/2.</p>
  
  <p>Alternatively, I have also the data split up into a bunch of dataframes without duplicate gen values, and I have been merging them to get the data frame above and am now trying to figure out how to combine them. If you can think of a way of combining the duplicates during the merge  please let me know.</p>