I want to group by condition with dynamic input column names.
df:
col1
a
b
c
d
a
c
d
b
a
b
d
I created function like below
fun1 <- function(df,column_name){
col_name1 = noquote(column_name)
out_df = df %>% group_by(col_name1)%>%dplyr::summarise('Count'=n())
return(out_df)
}
where column_name is string. Example: column_name = 'col1'
When apply that function it is giving below error:
Error: Must group by variables found in `.data`.
* Column `col_name1` is not found.
I'm getting above error even though column exists. Where have I gone wrong?