I am trying to write a function that takes a dataframe, a column that determines if a specific condition is met to subset the frame, a column with a numeric value, a grouping clause, and a subset name as arguments. 

I would like the function to then check to see which of the columns across a defined range has a value that is not NA, and then extract the column names of those columns and append them to the dplyr table generated by the function for each summary row that dplyr generates as per the grouping clause. I am doing this over hundreds of subsets of a much bigger much more complicated dataframe so this is why I need a function that I can use over and over again.

The example dataset is as follows, I have updated it with the expanded dataset 
 apologies tot those who tried to help with the other one:

```
structure(list(superKey = c("12015", "12016", "12017", "12018", 
"22015", "22016", "22017", "22018", "32015", "1722016", "1722017", 
"1722018", "1732015", "1732016", "1732017", "1732018", "1742015", 
"1752015", "1752016", "1752017", "1762015", "1762018", "1772016", 
"1772017", "1772018", "1782015", "1782016", "1782017", "1782018", 
"1792015", "1792016", "1792017", "1792018", "1802015", "1812018", 
"1822016", "1832015", "1832017", "1842015", "1842016", "1842017", 
"1842018", "1852016", "1852017", "1852018", "2112018", "2122015", 
"2122016", "2122017", "2122018", "2132015", "2132016", "2132017", 
"2132018", "2142015", "2142016", "2142017", "2142018", "2152015", 
"2152016", "2152017", "2152018", "2162016", "2162017", "2172015", 
"2172016", "2172017", "2172018", "2182015", "2182016", "2182017", 
"2182018", "2192016", "2192017", "2192018", "2202015", "2202016", 
"2202017", "2202018", "2212015", "2212016", "2212017", "2212018", 
"2222015", "2222018", "2232015", "2232016", "2232017", "2232018", 
"2242015", "2242016", "2302018", "2312015", "2312016", "2312017", 
"2312018", "2322016", "2322017", "2332015", "2332016", "2332017", 
"2332018", "2342016", "2342017", "2432018", "2442015", "2442016"
), reportDate = c("2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", 
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", 
"2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", "2016-12-31", 
"2017-12-31", "2018-12-31", "2015-12-31", "2015-12-31", "2016-12-31", 
"2017-12-31", "2015-12-31", "2018-12-31", "2016-12-31", "2017-12-31", 
"2018-12-31", "2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", 
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", 
"2018-12-31", "2016-12-31", "2015-12-31", "2017-12-31", "2015-12-31", 
"2016-12-31", "2017-12-31", "2018-12-31", "2016-12-31", "2017-12-31", 
"2018-12-31", "2018-12-31", "2015-12-31", "2016-12-31", "2017-12-31", 
"2018-12-31", "2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", 
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", 
"2016-12-31", "2017-12-31", "2018-12-31", "2016-12-31", "2017-12-31", 
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", 
"2016-12-31", "2017-12-31", "2018-12-31", "2016-12-31", "2017-12-31", 
"2018-12-31", "2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", 
"2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", "2015-12-31", 
"2018-12-31", "2015-12-31", "2016-12-31", "2017-12-31", "2018-12-31", 
"2015-12-31", "2016-12-31", "2018-12-31", "2015-12-31", "2016-12-31", 
"2017-12-31", "2018-12-31", "2016-12-31", "2017-12-31", "2015-12-31", 
"2016-12-31", "2017-12-31", "2018-12-31", "2016-12-31", "2017-12-31", 
"2018-12-31", "2015-12-31", "2016-12-31"), employerClass = c("class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class1", "class1", "class1", "class1", "class1", 
"class1", "class1", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class1", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2", "class2", "class2", "class2", "class2", "class2", "class2", 
"class2"), healthRegion = c("Region1", "Region1", "Region1", 
"Region1", "Region2", "Region2", "Region2", "Region2", "Region2", 
"Region3", "Region3", "Region3", "Region4", "Region4", "Region4", 
"Region4", "Region3", "Region3", "Region3", "Region3", "Region3", 
"Region3", "Region2", "Region2", "Region2", "Region3", "Region3", 
"Region3", "Region3", "Region2", "Region2", "Region2", "Region2", 
"Region3", "Region4", "Region4", "Region3", "Region3", "Region1", 
"Region1", "Region1", "Region1", "Region2", "Region2", "Region2", 
"Region2", "Region2", "Region2", "Region2", "Region2", "Region3", 
"Region3", "Region3", "Region3", "Region3", "Region3", "Region3", 
"Region3", "Region4", "Region4", "Region4", "Region4", "Region2", 
"Region2", "Region3", "Region3", "Region3", "Region3", "Region3", 
"Region3", "Region3", "Region3", "Region1", "Region1", "Region1", 
"Region3", "Region3", "Region3", "Region3", "Region4", "Region4", 
"Region4", "Region4", "Region3", "Region3", "Region3", "Region3", 
"Region3", "Region3", "Region4", "Region4", "Region1", "Region1", 
"Region1", "Region1", "Region1", "Region3", "Region3", "Region2", 
"Region2", "Region2", "Region2", "Region1", "Region1", "Region1", 
"Region2", "Region2"), contactID = c(1, 1, 1, 1, 2, 2, 2, 2, 
3, 172, 172, 172, 173, 173, 173, 173, 174, 175, 175, 175, 176, 
176, 177, 177, 177, 178, 178, 178, 178, 179, 179, 179, 179, 180, 
181, 182, 183, 183, 184, 184, 184, 184, 185, 185, 185, 211, 212, 
212, 212, 212, 213, 213, 213, 213, 214, 214, 214, 214, 215, 215, 
215, 215, 216, 216, 217, 217, 217, 217, 218, 218, 218, 218, 219, 
219, 219, 220, 220, 220, 220, 221, 221, 221, 221, 222, 222, 223, 
223, 223, 223, 224, 224, 230, 231, 231, 231, 231, 232, 232, 233, 
233, 233, 233, 234, 234, 243, 244, 244), funder1 = c(500, 500, 
500, 500, 500, 500, 500, 500, NA, NA, NA, NA, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, NA, NA, NA, 
NA, 500, 500, 500, 500, 500, 500, 500, 500, 500, NA, NA, NA, 
NA, NA, NA, NA, 500, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 500, 500, 500, 500, NA, NA, 500, 500, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 500, 500, NA, NA, NA, NA, 
NA, NA, NA, 500, 500, 500, 500, NA, NA, 500, NA, NA), funder2 = c(1000, 
1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, NA, NA, NA, NA, 
NA, NA, NA, 1000, NA, NA, NA, 1000, NA, 1000, 1000, 1000, NA, 
NA, 1000, 1000, 1000, 1000, 1000, 1000, 1000, NA, NA, 1000, 1000, 
1000, 1000, 1000, 1000, NA, NA, NA, 1000, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 1000, 1000, 1000, 1000, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, 1000, 1000, 1000, 1000, NA, NA, NA, NA, NA, NA, 
NA, 1000, 1000, NA, NA, NA, NA, 1000, 1000, NA, NA, NA), funder3 = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), funder4 = c(NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA), funder5 = c(2500, 2500, 
2500, 2500, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, 2500, 2500, 2500, 2500, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 2500, 2500, NA, NA, NA), others = c(3000, 
3000, 3000, 3000, NA, NA, NA, NA, 3000, 3000, 3000, 3000, NA, 
NA, NA, NA, 3000, NA, NA, NA, 3000, NA, NA, NA, NA, 3000, 3000, 
3000, 3000, 3000, 3000, 3000, 3000, NA, NA, NA, NA, NA, 3000, 
3000, 3000, 3000, NA, NA, NA, NA, NA, NA, NA, NA, 3000, 3000, 
3000, NA, NA, NA, NA, NA, NA, NA, 3000, 3000, 3000, 3000, 3000, 
3000, 3000, 3000, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 3000, 3000, NA, NA, 3000, 3000, 3000, 
3000, 3000, 3000, 3000, 3000, 3000, NA, NA, NA, NA, 3000, NA, 
NA, NA, 3000), total = c(7000, 7000, 7000, 7000, 1500, 1500, 
1500, 1500, 4000, 3000, 3000, 3000, 500, 500, 500, 500, 4500, 
500, 500, 500, 4500, 500, 1500, 1500, 1500, 3000, 3000, 4000, 
4000, 4500, 4500, 4500, 4500, 1500, 500, 500, 1500, 1500, 4000, 
4000, 4000, 4000, 0, 0, 0, 1500, 0, 0, 0, 0, 3000, 3000, 3000, 
0, 0, 0, 0, 0, 1500, 1500, 4500, 4500, 3000, 3000, 3500, 3500, 
3500, 3500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 7000, 7000, 4000, 4000, 3500, 
3500, 3000, 3000, 3000, 3000, 3000, 4000, 4000, 500, 500, 500, 
500, 6500, 3500, 500, 0, 3000), year = c("2015", "2016", "2017", 
"2018", "2015", "2016", "2017", "2018", "2015", "2016", "2017", 
"2018", "2015", "2016", "2017", "2018", "2015", "2015", "2016", 
"2017", "2015", "2018", "2016", "2017", "2018", "2015", "2016", 
"2017", "2018", "2015", "2016", "2017", "2018", "2015", "2018", 
"2016", "2015", "2017", "2015", "2016", "2017", "2018", "2016", 
"2017", "2018", "2018", "2015", "2016", "2017", "2018", "2015", 
"2016", "2017", "2018", "2015", "2016", "2017", "2018", "2015", 
"2016", "2017", "2018", "2016", "2017", "2015", "2016", "2017", 
"2018", "2015", "2016", "2017", "2018", "2016", "2017", "2018", 
"2015", "2016", "2017", "2018", "2015", "2016", "2017", "2018", 
"2015", "2018", "2015", "2016", "2017", "2018", "2015", "2016", 
"2018", "2015", "2016", "2017", "2018", "2016", "2017", "2015", 
"2016", "2017", "2018", "2016", "2017", "2018", "2015", "2016"
), serviceDivision = c("division1", "division1", "division1", 
"division1", "division2", "division2", "division2", "division2", 
"division1", "division1", "division1", "division1", "division2", 
"division2", "division2", "division2", "division1", "division2", 
"division2", "division2", "division2", "division2", "division2", 
"division2", "division2", "division3", "division3", "division3", 
"division3", "division1", "division1", "division1", "division1", 
"division2", "division2", "division2", "division2", "division2", 
"division1", "division1", "division1", "division1", "division1", 
"division1", "division1", NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "division2", 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), numFunders = c(4, 4, 4, 4, 2, 2, 2, 
2, 2, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 2, 2, 2, 1, 1, 2, 
2, 3, 3, 3, 3, 2, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 0, 0, 0, 
0, 1, 1, 1, 0, 0, 0, 0, 0, 2, 2, 3, 3, 1, 1, 2, 2, 2, 2, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 3, 3, 2, 2, 
1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 3, 2, 1, 0, 1), multiFunder = c(TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, 
TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE
), provFunders = c(8, 8, 7, 7, 3, 3, 3, 3, 2, 3, 2, 3, 1, 1, 
1, 1, 5, 2, 2, 1, 2, 1, 3, 3, 3, 2, 2, 3, 3, 5, 5, 5, 5, 3, 1, 
1, 3, 3, 4, 3, 3, 4, 1, 1, 1, 3, 1, 1, 1, 1, 2, 2, 2, 1, 3, 2, 
2, 2, 3, 4, 4, 4, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 
3, 3, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 2, 2, 3, 1, 1, 1, 1, 3, 3, 
3, 4, 3, 3, 3, 5, 1, 1, 1), nonProvFunders = c(3, 4, 4, 4, 0, 
0, 0, 0, 1, 5, 3, 5, 0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 1, 1, 1, 2, 
4, 3, 3, 2, 2, 3, 3, 1, 0, 0, 0, 0, 3, 4, 4, 4, 0, 0, 0, 0, 0, 
0, 0, 0, 2, 2, 2, 0, 1, 0, 0, 0, 0, 0, 1, 1, 4, 3, 1, 1, 1, 1, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 
3, 2, 4, 1, 1, 2, 1, 2, 2, 0, 0, 0, 1, 3, 3, 0, 0, 2), provFundedOnly = c(FALSE, 
FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, 
FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, 
FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, 
FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE), provincialFunding = c(1500, 
1500, 1500, 1500, 1500, 1500, 1500, 1500, 1000, 0, 0, 0, 500, 
500, 500, 500, 1500, 500, 500, 500, 1500, 500, 1500, 1500, 1500, 
0, 0, 1000, 1000, 1500, 1500, 1500, 1500, 1500, 500, 500, 1500, 
1500, 1000, 1000, 1000, 1000, 0, 0, 0, 1500, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 1500, 1500, 1500, 1500, 0, 0, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 
500, 500, 500, 500, 500, 1500, 1500, 1500, 1500, 500, 500, 0, 
0, 0, 0, 0, 1000, 1000, 500, 500, 500, 500, 1000, 1000, 500, 
0, 0), nonProvincialFunding = c(5500, 5500, 5500, 5500, 0, 0, 
0, 0, 3000, 3000, 3000, 3000, 0, 0, 0, 0, 3000, 0, 0, 0, 3000, 
0, 0, 0, 0, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 0, 
0, 0, 0, 0, 3000, 3000, 3000, 3000, 0, 0, 0, 0, 0, 0, 0, 0, 3000, 
3000, 3000, 0, 0, 0, 0, 0, 0, 0, 3000, 3000, 3000, 3000, 3000, 
3000, 3000, 3000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 5500, 5500, 2500, 2500, 3000, 3000, 3000, 3000, 3000, 3000, 
3000, 3000, 3000, 0, 0, 0, 0, 5500, 2500, 0, 0, 3000), agencySize = c("greater than $15M", 
"greater than $15M", "greater than $15M", "greater than $15M", 
"greater than $15M", "greater than $15M", "greater than $15M", 
"greater than $15M", "less than $1M", "$7M - $15M", "$7M - $15M", 
"$7M - $15M", "$1M - $2M", "$1M - $2M", "$1M - $2M", "$1M - $2M", 
"$2M - $4M", "less than $1M", "less than $1M", "less than $1M", 
"$2M - $4M", "$2M - $4M", "$4M - $7M", "$4M - $7M", "$4M - $7M", 
"$1M - $2M", "$1M - $2M", "$2M - $4M", "$2M - $4M", "$2M - $4M", 
"$2M - $4M", "$4M - $7M", "$4M - $7M", "$2M - $4M", "less than $1M", 
"$1M - $2M", "$2M - $4M", "$2M - $4M", "$2M - $4M", "$2M - $4M", 
"$4M - $7M", "$4M - $7M", "$1M - $2M", "$1M - $2M", "$1M - $2M", 
"less than $1M", "less than $1M", "less than $1M", "less than $1M", 
"less than $1M", "$1M - $2M", "$2M - $4M", "$2M - $4M", "$1M - $2M", 
"less than $1M", "less than $1M", "less than $1M", "less than $1M", 
"$4M - $7M", "$4M - $7M", "$4M - $7M", "$4M - $7M", "greater than $15M", 
"greater than $15M", "$2M - $4M", "$2M - $4M", "$2M - $4M", "$2M - $4M", 
"$1M - $2M", "$1M - $2M", "$1M - $2M", "$1M - $2M", "$2M - $4M", 
"$2M - $4M", "$2M - $4M", "less than $1M", "less than $1M", "less than $1M", 
"less than $1M", "less than $1M", "less than $1M", "$1M - $2M", 
"$1M - $2M", "$7M - $15M", "$7M - $15M", "greater than $15M", 
"greater than $15M", "greater than $15M", "greater than $15M", 
"$1M - $2M", "$1M - $2M", "$2M - $4M", "less than $1M", "less than $1M", 
"less than $1M", "less than $1M", "$1M - $2M", "$1M - $2M", "less than $1M", 
"less than $1M", "less than $1M", "less than $1M", "$2M - $4M", 
"$2M - $4M", "$2M - $4M", "$1M - $2M", "$1M - $2M"), funder1funded = c(TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, 
FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE), funder13funded = c(TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, 
TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, 
FALSE), funder2funded = c(FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE), funder3funded = c(FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE), funder4funded = c(TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE, FALSE, FALSE, FALSE), funder5funded = c(TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), sectorFunded = c("TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE", 
"TRUE", "TRUE"), totHolder = c(7000, 7000, 7000, 7000, 1500, 
1500, 1500, 1500, 4000, 3000, 3000, 3000, 500, 500, 500, 500, 
4500, 500, 500, 500, 4500, 500, 1500, 1500, 1500, 3000, 3000, 
4000, 4000, 4500, 4500, 4500, 4500, 1500, 500, 500, 1500, 1500, 
4000, 4000, 4000, 4000, 0, 0, 0, 1500, 0, 0, 0, 0, 3000, 3000, 
3000, 0, 0, 0, 0, 0, 1500, 1500, 4500, 4500, 3000, 3000, 3500, 
3500, 3500, 3500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 
500, 500, 500, 500, 500, 500, 500, 500, 7000, 7000, 4000, 4000, 
3500, 3500, 3000, 3000, 3000, 3000, 3000, 4000, 4000, 500, 500, 
500, 500, 6500, 3500, 500, 0, 3000)), row.names = c(NA, -107L
), class = c("tbl_df", "tbl", "data.frame"))

```

Please note that provincialFunding is the sum of funders 1,2, and 3 and nonProvincialFunding is the sum of funders 4,5 and others.

The grouping clause passed to the function for this example is:

```
GRclauseSDregion <- c("year", "employerClass", "multiFunder", "serviceDivision", "healthRegion")

```

There are multiple grouping clauses;

```
GRsectorProfile <- c("year", "employerClass", "multiFunder")
GRclass1SD <- c("year", "employerClass", "multiFunder", "serviceDivision")
GRsectorRegion <- c("year", "employerClass", "multiFunder", "healthRegion")
GRclass1SDregion <- c("year", "employerClass", "multiFunder", "serviceDivision", "healthRegion")
GRsectorAgencySize <- c("year", "employerClass", "multiFunder", "agencySize")
GRclass1AgencySize <- c("year","employerClass", "multiFunder", "agencySize")
GRclass1SDagencySize <- c("year", "employerClass", "multiFunder", "serviceDivision", "agencySize")
GRclass1SDregionAgencySize <- c("year", "employerClass", "multiFunder", "serviceDivision", "healthRegion", "agencySize")
GRnonCLASS1AregionAgencySize <- c("year", "employerClass", "multiFunder", "healthRegion", "agencySize")
GRclass1RegionAgencySize <- c("year", "employerClass", "multiFunder", "healthRegion", "agencySize")

```

This is where I have gotten to:

```
# collapse function (funder)
collapsePassFunderArray <- function(df, funderTrueCol, fundingCol, groupClause, name) {
  funderTrueHolder <- enquo(funderTrueCol)
  fundingColHolder <- enquo(fundingCol)
  newDf <- df %>% 
    filter((!!funderTrueHolder) == TRUE) %>% 
    group_by(.dots = groupClause) %>% 
    summarise(funderName = name, 
              totFund = sum(total),
              minFunder = min(numFunders),
              maxFunder = max(numFunders),
              avgFunder = mean(numFunders, na.rm = TRUE),
              medianFunder = median(numFunders, na.rm = TRUE),
              provPerc = sum(provincialFunding)/sum(total),
              nonProvPerc = sum(nonProvincialFunding)/sum(total),
              funderPercProv = sum((!!fundingColHolder))/sum(provincialFunding),
              funderPercTot = sum((!!fundingColHolder))/sum(total),
              numAgencies = n_distinct(contactID),
              funders = simplify2array(apply(df[8:13], 1, 
                                            function(x)paste(names(df[6:11]) [which(!is.na(x))], collapse = " ")))
    )
}

```

Please note that the dataframe columns being selected [6:11] are those columns that would have the funders under scrutiny. This could change over time but I don't mind making the changes manually.

The following code produces the desired output when applied to the full dataset (the desired output being the space separated list of funders in the funders variable):

```
reproTable$funders <- simplify2array(apply(reproTable[6:11], 1, 
                                           function(x)paste(names(reproTable[8:13]) [which(!is.na(x))], collapse = " ")))

```

I run the following function call:

```
test1 <- collapsePassFunderArray(reproTable, funder1funded, funder1, GRclauseSDregion, "All")

```

Which gives the following error:

```
Error: Column `funders` must be length 1 (a summary value), not 107 

```

Here is the desired output on the assumption that we are using the GRsectorRegion <- c("year", "employerClass", "multiFunder", "healthRegion") grouping clause as per user @akrun request:

```
https://pastebin.com/1Z8vRLir

```

Sorry I had to use pastebin to paste the desired output source it went over the character limit.

Thank you to those who have tried to crack this I have tried to adapt the code but have run into the problems described in the comments.