I would like to add a new column that is titled "pop sum" which takes the sum of all rows that has population data and is grouped by location. I tried group_by with Building and then sum = sum(pop) but that did work. I will just show one building but there are 30+ UNIQUE buildings Reference dataframe below:
`Date Ran` Year Month Building Population MonthN
<dttm> <dbl> <chr> <fct> <num> <chr>
1 2018-09-28 00:00:00 2018 September ALEX 1196 Sep
2 2018-08-30 00:00:00 2018 August ALEX 1172 Aug
3 2018-07-19 00:00:00 2018 July ALEX 1171 Jul
4 2018-06-30 00:00:00 2018 June ALEX 1167 Jun
5 2018-05-11 00:00:00 2018 May ALEX 1154 May
6 2018-04-09 00:00:00 2018 April ALEX 1154 Apr
Desired output would like something like this:
`Date Ran` Year Month Building Population MonthN Pop Sum
<dttm> <dbl> <chr> <fct> <dbl> <chr> <num>
1 2018-09-28 00:00:00 2018 September ALEX 1196 Sep 7014
2 2018-08-30 00:00:00 2018 August ALEX 1172 Aug 7014
3 2018-07-19 00:00:00 2018 July ALEX 1171 Jul 7014
4 2018-06-30 00:00:00 2018 June ALEX 1167 Jun 7014
5 2018-05-11 00:00:00 2018 May ALEX 1154 May 7014
6 2018-04-09 00:00:00 2018 April ALEX 1154 Apr 7014
A function or for loop would be great but if there are any R packages I could load in to generate new column that would be great