I have a df in which each entry has an assigned grouped ID, like:
id_person income id_family
001 100 A1
002 120 B2
003 100 B5
004 220 A1
005 300 A2
And now I need to assign a new variable for each id_person, summing up the variable income
of all entries with the same id_family
. Such as:
id_person income id_family family_income
001 100 A1 220
002 120 B2 120
003 100 B5 400
004 220 A1 220
005 300 B5 400
I do not wish to create a new grouped_df
, neither do I need to see this variable summarized for now.
How can I give this command using R?