I am trying to create a function which dynamically filter the value in data and then summarize it accordingly...
like we have drop down question below if a person select sales the he need to specify number, else he will get a drop down options (state or team) definition of column is as_character while reading database.
Sample Data
Focusing Area Answer
transfer NY
sale 130
sale 110
transfer CA
Developing Team
Developing Product
transfer MI
sale 115
i want a to standardize a function like,it will filter sales from data and summarize accordingly.
Text_tab_filter<-function(data,filter_var, Text_var,filter_val,title)
{filter_var <- ensym(filter_var)
val_var <- ensym(Text_var)
dat1<-data%>% select(!!filter_var,!!Text_var)
dat1<- dat1%>% filter(!!filter_var==!!filter_val)
summ_tab1<- as.numeric(dat1[[Text_var]]) %>% filter(!is.na(!!Text_var)) %>% summarise(
q25 = round(quantile(!!Text_var, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[2],digits = 1),
Median =round(quantile(!!Text_var, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[3],digits = 1),
Average = round( mean(!!Text_var, na.rm=TRUE),digits = 1),
q75 = round(quantile(!!Text_var, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[4],digits = 1) ,
N = sum(!is.na(!!Text_var)))
}
error getting:
But getting error Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')"
output should be like below
N 25th percentile Median Average 75th percentile
Sales 3 107 115 118.3 112