Hello,
I am trying to make a function with summarize, to use with several dataframes. I guess I am missing something trivial, but cannot figure out what.
A basic call I am trying to build on is:
library(tidyverse)
mtcars |> group_by(cyl) |> summarize("mean"= mean(mpg), "sd"= sd(mpg), "median" = median(mpg))
My attempt at a function is:
library(tidyverse)
f.stat <- function(df,dv){
df |> group_by(cyl) |> summarize("mean"= mean(dv), "sd"= sd(dv), "median" = median(dv))
}
f.stat(mtcars, mpg)
It does not work with the dv supplied this way, but I don't know how to fix it. How should I do it properly?