I am trying to write a function to create summary table. The variables i am interested to summarise might change, therefore, I would like to have it in a function. I followed the example from the dpylr vignette about NSE, but it is not working for me for some reason. Here is the function:
print(agegroup) # this is a string
table_summary <- function (data, group_by1){
quo_group_by1 = quo(group_by1)
print(quo_group_by1)
data %>%
dplyr::group_by(!! quo_group_by1) %>%
dplyr::summarise(N = n()) %>%
dplyr::mutate(pct = paste0((round(N/sum(N)*100, 2))," %"))
}
table_summary(clientData, agegroup)
and i get the following error :
[1] "ag5"
<quosure>
expr: ^group_by1
env: 0x7faaec29e030
Error: Column `group_by1` is unknown
How can i fix this?