Let’s create an input table with three columns. This contains an assortment of values that could potentially undergo some substitution via sub_values().
# A tibble: 7 × 3
num_1 int_1 lett
<dbl> <int> <chr>
1 -0.01 1 A
2 74 -100000 B
3 NA 800 C
4 0 5 D
5 500 NA E
6 0.001 1 F
7 84.3 -32 G
Values in the table body cells can be replaced by specifying which values should be replaced (in values) and what the replacement value should be. It’s okay to search for numerical or character values across all columns and the replacement value can also be of the numeric or character types.
For the most flexibility, it’s best to use the fn argument. With that you need to ensure that the function you provide will return a logical vector when invoked on a column of cell values, taken as x (and, the length of that vector must match the length of x).
tbl |>gt() |>sub_values(fn =function(x) x >=0& x <50,replacement ="Between 0 and 50" )