Suppose I have a data.frame
df like this:
df <- tribble(
~id, ~name, ~group, ~score,
01, "john", "group_1", 80,
01, "john", "group_3", 85,
01, "john", "group_2", 75,
02, "adam", "group_2", 80,
02, "adam", "group_1", 85
)
I want to find the individual sums for the score of each group and store them in a new variable,
for example, the variable avg_group_1
should have the value 82.5. (because the group_1 scores are 80 and 85)