Is there a universal way to get the name of the summarized variable into the tibble with results?
After running a command like below:
library(tidyverse) mtcars |> group_by(cyl) |> summarize("mean"= mean(mpg), "sd"= sd(mpg), "median" = median(mpg))
I get a 3x4 tibble with columns "cyl", "mean", "sd", "median". It is fine, but I would also like to have a column "name" where the values would be the name of the summarized variable (the same for all rows, obviously).
Would be even nicer if I could get a command with summarize where I only mention the variable once (e.g. mpg in the example above).
Can anybody help me here?