replacing text from the table not working properly

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.


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", 

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"),
  Min = getOption("Min_n"),
  Max = getOption("Max_n")

for(n in names(replacements_list)){
  i <- replacements_list[[n]]
  df <-  mutate(df,
                           function(x) str_replace_all(x,

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


The screenshots that you shared dont match the code you provided.

First, I will say there is nothing that would filter the df, so it wouldnt lose rows; your code that you provided doesnt cause any rows to go away.

Second, the mutate in the for loop, is not similar to what you were advised to use in your previous request to help, as it effectively only retains the final replacement made in the loop.

you start with df; within each run of the loop there may be an adjustment to the df but you put this into df1, so the next time the loop runs the previous change is disregarded.

now i got it when i upgraded the R studion from 4.2.1 to 4.3.2 , and now its working fine .
but why it was not working on lower versions..??
i was running the same code above nad it was not working

I tested that your corrected code (where you address the df1/df issue) runs on R 3.6.2 as well. (it does)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.