I have a scenario where I get the column index in a variable and the I have to group by and summarise by that variable
 col_index <- which(sapply(dataframe, function(x) any(x == "Area of Maintenance")))
> col_index
  X__7 
  8 
Now I want to group by col_index value like following
df%>%
group_by(df[col_index]) %>%
summarise(count = n()) %>%
as.data.frame()
It gives me following error.
Error in mutate_impl(.data, dots) : 
Evaluation error: Column index must be at most 1 if positive, not 8.
col_index has a dynamic value. How can I do it in r?
 
     
    