<- dplyr::tibble(num = c(10^(-4:2), 0, NA))
tbl
tbl
# A tibble: 9 × 1
num
<dbl>
1 0.0001
2 0.001
3 0.01
4 0.1
5 1
6 10
7 100
8 0
9 NA
sub_small_vals()
functionLet’s generate a simple, single-column tibble that contains an assortment of values that could potentially undergo some substitution.
# A tibble: 9 × 1
num
<dbl>
1 0.0001
2 0.001
3 0.01
4 0.1
5 1
6 10
7 100
8 0
9 NA
The tbl
contains a variety of smaller numbers and some might be small enough to reformat with a threshold value. With sub_small_vals()
we can do just that:
num |
---|
<0.01 |
<0.01 |
0.01 |
0.10 |
1.00 |
10.00 |
100.00 |
0.00 |
NA |
Small and negative values can also be handled but they are handled specially by the sign
parameter. Setting that to "-"
will format only the small, negative values.
num |
---|
<abs(-0.01) |
<abs(-0.01) |
−0.01 |
−0.10 |
−1.00 |
−10.00 |
−100.00 |
0.00 |
NA |
You don’t have to settle with the default threshold
value or the default replacement pattern (in small_pattern
). This can be changed and the "{x
“} in small_pattern
(which uses the threshold
value) can even be omitted.