I have the following somewhat complicated problem. Consider the following two data frames
df
  ID cat month_1 month_2
1  1   A       3       1
2  1   B       2       2
3  1   C       3       4
4  2   A       3       6
5  3   D       5       2
6  3   B       2       9
> df2
  ID month_number
1  1      month_1
2  1      month_2
3  2      month_1
4  2      month_2
5  3      month_1
6  3      month_2
Now, I want to do the following: I want to create a new column in df2, displaying the sum of an related to the ID, in the specific month. I.e., in the first df it can be seen that the person with ID 1 has a total sum of 3+2+3 = 8 in month 1 and 7 in month 2. I want to mutate this, respectively to the correct month. The desired output would be (Now computed by hands)
desired_df
  ID month_number grand_total
1  1      month_1           8
2  1      month_2           7
3  2      month_1           3
4  2      month_2           6
5  3      month_1           7
6  3      month_2          11
I want to show my code, but I do not have any. Could anyone help me?
 
    