I have the following data frame structure:
ID | conception_date | birth_date | med_1 | med_2 | med_3 | med_4 | ... | med_n |
---|---|---|---|---|---|---|---|---|
A | xxxx | xxxx | 1 | 0 | 0 | 0 | ... | |
A | xxxx | xxxx | 0 | 1 | 0 | 0 | ... | |
A | xxxx | xxxx | 0 | 0 | 1 | 0 | ... | |
B | xxxx | xxxx | 1 | 0 | 0 | 0 | ... | |
B | xxxx | xxxx | 0 | 1 | 0 | 0 | ... | |
B | xxxx | xxxx | 0 | 0 | 1 | 0 | ... | |
B | xxxx | xxxx | 0 | 0 | 0 | 1 | ... | |
C | xxxx | xxxx | 1 | 0 | 0 | 0 | ... | |
C | xxxx | xxxx | 0 | 0 | 0 | 1 | ... |
I would like to group people by their ID
, conception_date
and birth_date
in order to keep one line per person while summing medications per column per groupement. So the structure would become:
ID | conception_date | birth_date | med_1 | med_2 | med_3 | med_4 | ... | med_n |
---|---|---|---|---|---|---|---|---|
A | xxxx | xxxx | 1 | 1 | 1 | 0 | ||
B | xxxx | xxxx | 1 | 1 | 1 | 1 | ||
C | xxxx | xxxx | 1 | 0 | 0 | 1 |