I have a data frame which looks like this:
year country inhabitants
1 1 A 15
2 2 A 10
3 3 A 24
4 1 B 76
5 2 B 69
6 3 B 58
7 1 C 120
8 2 C 131
9 3 C 128
Now, I would like to create the sum of "inhabitants" for each year, over all countries. I.e., my solution would look like:
year country inhabitants sum_inhabitants
1 1 A 15 211
2 2 A 10 210
3 3 A 21 207
4 1 B 76 211
5 2 B 69 210
6 3 B 58 207
7 1 C 120 211
8 2 C 131 210
9 3 C 128 207
My original data frame contains many more observations, which is why I can't do the computation by hand.