<- dplyr::tibble(num = c(0, NA, 10^(8:14)))
tbl
tbl
# A tibble: 9 × 1
num
<dbl>
1 0
2 NA
3 1e 8
4 1e 9
5 1e10
6 1e11
7 1e12
8 1e13
9 1e14
sub_large_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
2 NA
3 1e 8
4 1e 9
5 1e10
6 1e11
7 1e12
8 1e13
9 1e14
The tbl
object contains a variety of larger numbers and some might be larger enough to reformat with a threshold value. With sub_large_vals()
we can do just that:
num |
---|
0.00 |
NA |
100,000,000.00 |
1,000,000,000.00 |
10,000,000,000.00 |
100,000,000,000.00 |
≥1e+12 |
≥1e+12 |
≥1e+12 |
Large negative values can also be handled but they are handled specially by the sign
parameter. Setting that to "-"
will format only the large values that are negative. Notice that with the default large_pattern
value of ">={x
“} the ">="
is automatically changed to "<="
.
num |
---|
0.00 |
NA |
−100,000,000.00 |
−1,000,000,000.00 |
−10,000,000,000.00 |
−100,000,000,000.00 |
≤-1e+12 |
≤-1e+12 |
≤-1e+12 |
You don’t have to settle with the default threshold
value or the default replacement pattern (in large_pattern
). This can be changed and the "{x
“} in large_pattern
(which uses the threshold
value) can even be omitted.