i have created a function which is working fine, now i want to take the labels from global option in rmarkdown to change the labels of Mean , median, percentile
So in global option if someone want to show mean as Avg or averagea then it should change same as percenties25 or 75
i was trying the below update but it was not working
library(expss)
library(dplyr)
df <- mtcars
df <- head(df,3)
var <- "hp"
df$vs <- 1
banner1 <- list(df$vs)
fun1 <- function(data, var, Banner,p25 = getOption("percentile25", default = "25th percentile"),
perc_75 = getOption("percentile75", default = "75th percentile")) {
var1 <- rlang::parse_expr(var)
perc_25 <- function(x) quantile(x, type = 6, probs = seq(0, 1, 0.25), na.rm = TRUE)[2]
perc_75 <- function(x) quantile(x, type = 6, probs = seq(0, 1, 0.25), na.rm = TRUE)[4]
Mean <- function(x) mean(x, na.rm = TRUE)
valid_n <- function(x) sum(!is.na(x))
t1 <- cross_fun(
data,
data[[var1]],
col_vars = Banner,
fun = combine_functions(
"25th Perc" = perc_25,
"Mean" = Mean,
"Median" = Median,
"75th Perc" = perc_75,
"Valid N" = valid_n
)
)
return(t1)
}
# Example usage with masking set to TRUE
result <- fun1(df, var = "hp", Banner = banner1,)
print(result)
I was trying like below but it was not working .
t1 <- cross_fun(
data,
data[[var1]],
col_vars = Banner,
fun = combine_functions(
!!p25 = perc_25,
"Mean" = Mean,
"Median" = Median,
!!p75 = perc_75,
"Valid N" = valid_n
)
)