View source: R/cols_align_decimal.R
cols_align_decimal | R Documentation |
For numeric columns that contain values with decimal portions, it is
sometimes useful to have them lined up along the decimal mark for easier
readability. We can do this with cols_align_decimal()
and provide any
number of columns (the function will skip over columns that don't require
this type of alignment).
cols_align_decimal(data, columns = everything(), dec_mark = ".", locale = NULL)
data |
The gt table data object
This is the gt table object that is commonly created through use of the
|
columns |
Columns to target
The columns for which decimal alignment should be applied. Can either be a
series of column names provided in |
dec_mark |
Decimal mark
The character used as a decimal mark in the numeric values to be aligned.
If a locale value was used when formatting the numeric values then |
locale |
Locale identifier
An optional locale identifier that can be used to obtain the type of
decimal mark used in the numeric values to be aligned (according to the
locale's formatting rules). Examples include |
An object of class gt_tbl
.
Let's put together a two-column table to create a gt table. The first
column char
just contains letters whereas the second column, num
, has a
collection of numbers and NA
values. We could format the numbers with
fmt_number()
and elect to drop the trailing zeros past the decimal mark
with drop_trailing_zeros = TRUE
. This can leave formatted numbers that are
hard to scan through because the decimal mark isn't fixed horizontally. We
could remedy this and align the numbers by the decimal mark with
cols_align_decimal()
.
dplyr::tibble( char = LETTERS[1:9], num = c(1.2, -33.52, 9023.2, -283.527, NA, 0.401, -123.1, NA, 41) ) |> gt() |> fmt_number( columns = num, decimals = 3, drop_trailing_zeros = TRUE ) |> cols_align_decimal()
5-2
v0.8.0
(November 16, 2022)
Other column modification functions:
cols_add()
,
cols_align()
,
cols_hide()
,
cols_label()
,
cols_label_with()
,
cols_merge()
,
cols_merge_n_pct()
,
cols_merge_range()
,
cols_merge_uncert()
,
cols_move()
,
cols_move_to_end()
,
cols_move_to_start()
,
cols_nanoplot()
,
cols_unhide()
,
cols_units()
,
cols_width()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.