I'm fairly new to R and I've been struggling with how to make this work:
I'm looking to pool the population numbers across several years (to match a smaller pooled dataset). So instead of having yearly population data, I would combine rows in "three-year" intervals and take an average (eg. (2007+2008+2009)/3). This would be done for all regions (columns).
My current dataframe:
year | CAN | ONT | AL | BC | atlantic | mansask |
---|---|---|---|---|---|---|
2007 | 32887928 | 12764195 | 3514031 | 4290988 | 2327238 | 2191414 |
2008 | 33245773 | 12882625 | 3595755 | 4349412 | 2333027 | 2215120 |
2009 | 33628571 | 12997687 | 3679092 | 4410679 | 2344786 | 2243371 |
2010 | 34005274 | 13135063 | 3732573 | 4465924 | 2358767 | 2272355 |
2011 | 34342780 | 13263544 | 3790191 | 4499139 | 2369074 | 2300077 |
2012 | 34750545 | 13413702 | 3880755 | 4546290 | 2373250 | 2336283 |
2013 | 35152370 | 13555754 | 3997950 | 4590081 | 2371356 | 2370413 |
2014 | 35535348 | 13680425 | 4108416 | 4646462 | 2371210 | 2401551 |
2015 | 35832513 | 13789597 | 4177527 | 4694699 | 2371095 | 2426572 |
2016 | 36264604 | 13976320 | 4236376 | 4757658 | 2385779 | 2466703 |
My ideal transformation (I didn't rework the numbers in this example):
year | CAN | ONT | AL | BC | atlantic | mansask |
---|---|---|---|---|---|---|
2007-2009 | 32887928 | 12764195 | 3514031 | 4290988 | 2327238 | 2191414 |
2010-2012 | 33245773 | 12882625 | 3595755 | 4349412 | 2333027 | 2215120 |
2013-2015 | 33628571 | 12997687 | 3679092 | 4410679 | 2344786 | 2243371 |
2016-2018 | 34005274 | 13135063 | 3732573 | 4465924 | 2358767 | 2272355 |
Thanks in advance for any advice/help!