"Sepal.Width") #> Species Sepal.Width #> <fct> <dbl> #> 1 setosa 3.43 #> 2 versicolor 2.77 #> 3 virginica 2.97 mean_by <- function(data, by, var) { data %>% group_by(.data[[by]]) %>% summarise("{var}" := mean(.data[[var]], na.rm = TRUE)) } Use single {
to glue
the string