I would like to create a variable with mutate() that will have values equal to the name of a given variable. I need this to change dynamically. Apologies I am fairly new to R so let me know if this doesn’t make sense.
This is the function that I wrote:
proportions <- function(data, var_1) {
var_1 <- enquo(var_1)
prop_all <- data %>%
filter(!!var_1>=0)%>%
group_by(!!var_1)%>%
summarise(Percent=round(survey_mean(vartype="ci")*100,0),
Total = unweighted(n()))%>%
mutate(N = sum(Total))%>%
mutate(Indicator = label(!!var_1))
}
Here the ‘Indicator’ variable has the label of var_1 as values. I would like it to have as values the name of var_1.
user24831703 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.