Hi everyone
I have a dataset with multiple rows per "id" and would like to combine these rows.
Some columns (in the example dataset W1-W3) include relative frequencies. I would like a dataset with one row per id and the values of the average relative frequencies in the columns W1:W3.
Example dataset:
df_mp <- data.frame(id = c(1, 1, 1, 2, 2),
W1 = c(3.4, 2.5, 1.4, 0, 1.1),
W2 = c(1.6, 2.3, 0.7, 1.1, 8.1),
W3 = c(0, 0.1, 0.3, 2, 3.1))
id W1 W2 W3
1 1 3.4 1.6 0.0
2 1 2.5 2.3 0.1
3 1 1.4 0.7 0.3
4 2 0.0 1.1 2.0
5 2 1.1 8.1 3.1
The new dataset should look as follows:
id W1 W2 W3
1 1 2.433333 1.533333 0.1333333
2 2 0.550000 4.600000 2.5500000
The values in W1:W3 are the "average relative frequencies": all the relative frequencies of each "id" summed up and divided by the number of rows that were combined for that "id".
Thank you in advance for your help