I have a dataframe which contains some duplicates. I want to sum rows of two columns where there is a duplicate and then delete the unwanted row.
Here is an example of the data,
Year ID Lats Longs N n c_id
2015 200 30.5417 -20.5254 150 30 4142
2015 200 30.5417 -20.5254 90 50 4142
I want to sum columns N and n into one row. the rest of the information i.e. Lats , Longs , ID and Year is to remain the same e.g.,
Year ID Lats Long N n c_id
2015 200 30.5417 -20.5254 240 80 4142
Solution using
data.table
:Solution using
plyr
: