I have written a group_by summarise function to avoid typing it out every time. I want to run for multiple variables (columns) in my dataframe. Is there a way I can iterate this, as opposed to typing out new variable each time?
summary_function <- function(data , var) {
data |>
summarise(N = n() ,
'Median_{{ var }}' := median({{ var }} , na.rm = T) ,
IQR = IQR({{ var }} , na.rm = T) ,
Q1 = quantile({{ var }} , probs = 0.25 , na.rm = T) ,
Q3 = quantile({{ var }} , probs = 0.75 , na.rm = T) ,
min = min({{ var }}) ,
max = max({{ var }})
)
}
I want to repeat this for several variables in df, e.g. var1, var2, var3 etc
I’m struggling to do this lapply, which I feel could be the answer here?
New contributor
tacospider is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.