Hello, everyone. I have these two datasets.
id number density
1 467800075 7 47.4167
2 488141762 7 44.5417
3 488141768 5 156.9275
...
id number density
1 467800075 2 810.7656
2 488141762 5 1057.1979
3 488141768 3 865.4010
...
I want to calculate weighted sum of two tables per each id and the table I want to get ultimately is like this :
id number weighted_density
1 467800075 9 ...
2 488141762 12 ...
3 488141768 8 ...
...
Of course I know the equation that calculating weighted sum is
{(number of x1 * figure of x1) + (number of x2 * figure of x2)} / (number of x1 + number of x2)
and generally we use functions like 'group_by' or 'aggregate' to get summated value by each id,
but don't have any idea how to make the table above.
I would be very appreciate if you help me. How should I code to derive that?