I have a data frame that has some records that are duplicated and I need to aggregate the duplicates so there is a unique record per row.
An example:
Col1 Col2 Col3 Col4
A 0.170 83 0.878
B 0.939 103 0.869
C 0.228 80 0.935
D 0.566 169 0.851
D 0.566 137 0.588
E 0.703 103 0.636
I need to weight the average of Col4 with Col3, and sum Col3. So my result would be:
Col1 Col2 Col3 Col4
A 0.17 83 0.878
B 0.939 103 0.869
C 0.228 80 0.935
D 0.566 306 0.733
E 0.703 103 0.636
Usually I would use the aggregate function but I can't seem to find a solution to include two different function types. Is there another way I can accomplish this? I am effectively ignoring Col 2 since the granularity before merging with the data that brought in Col3 and Col4 was one record per row, and now it is being duplicated.
Thank you!!