Hi @str_guru. Admittedly not the most elegant solution, but below is a function that replaces the values as you specify. Please note, the function follows the description where two of the three cases are replaced with empty characters "" (but the examples provided replace everything with "*").
library(stringr)
# function to replace values
replace_values = function(i) {
# identify position of each category of interest (Max, Min, etc.) in vector
mymax = which(str_detect(i$row_labels, 'Max'))
mymin = which(str_detect(i$row_labels, 'Min'))
myave = which(str_detect(i$row_labels, 'Ave'))
mytotal = which(str_detect(i$row_labels, 'Total'))
out = i
Total = out$`1`[mytotal]
# preserve formatting
out$`1` = sprintf("%.1f", round(out$`1`,1))
# check and overwrite if true
if(Total == 5) {out$`1`[myave] = ''}
if(Total <= 4) {out$`1`[mymax] = ''}
if(Total <= 3) {out$`1`[mymin] = '*'}
out
}
t1
# Sample case (force Total = 5)
t2 = t1
t2$`1`[4] = 5
t2 |> replace_values()
# Sample case (force Total <= 4)
t3 = t1
t3$`1`[4] = 3.5
t3 |> replace_values()