I have created a function which is creating a table (df structure) like below, now i want to replace the lables of statistics (mean, median, max, min,percentile25...etc.) from table .its working but it reducing the table and eliminating the rest of stats.
library(tidyverse)
df <- structure(list(row_labels = c("Text[Sample_table]: context of table|25th percentile.25%",
"Text[Sample_table]: context of table|Mean", "Text[Sample_table]: context of table|Median",
"Text[Sample_table]: context of table|75th percentile.75%", "Text[Sample_table]: context of table|Max",
"Text[Sample_table]: context of table|Min", "Text[Sample_table]: context of table|Total Cases",
"Text[Sample_table]: context of table|Missing Values"), Total = c(62.5,
913.75, 933, 1745.75, 1749, 40, 4, 0), Col1 = c(62.5, 913.75,
933, 1745.75, 1749, 40, 4, 0), COl2 = c(1736, 1736, 1736, 1736,
1736, 1736, 1, 0)), row.names = c(NA, -8L), class = c("etable",
"data.frame"))
options(percentile25 = "25th Percentil")
options(percentile75 = "75th Percentil")
options(Mean_n = "Meana")
options(Med_n = "Mediana")
options(Min_n = "Minn")
options(Max_n = "Maxx")
replacements_list <- list(
"25th percentile.25%" = getOption("percentile25"),
"75th percentile.75%" = getOption("percentile75"),
Mean=getOption("Mean_n"),
Median=getOption("Med_n"),
Min = getOption("Min_n"),
Max = getOption("Max_n")
)
for(n in names(replacements_list)){
i <- replacements_list[[n]]
df <- mutate(df,
across(where(is.character),
function(x) str_replace_all(x,
pattern=n,
replacement=i)))
}
The expected output should be replaced lables with all stats like below also after changing labels from global option
but i am getting the below stats only