cols_move_to_end {gt} | R Documentation |
Move one or more columns to the end
Description
It's possible to move a set of columns to the end of the column series, we
only need to specify which columns
are to be moved. While this can be done
upstream of gt, this function makes to process much easier and it's less
error prone. The ordering of the columns
that are moved to the end is
preserved (same with the ordering of all other columns in the table).
Usage
cols_move_to_end(data, columns)
Arguments
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 the moving operations should be applied. Can either
be a series of column names provided in |
Details
The columns supplied in columns
must all exist in the table. If you need to
place one or columns at the start of the column series, cols_move_to_start()
should be used. More control is offered with cols_move()
, where columns
could be placed after a specific column.
Value
An object of class gt_tbl
.
Examples
For this example, we'll use a portion of the countrypops
dataset to
create a simple gt table. Let's move the year
column, which is the
middle column, to the end of the column series with cols_move_to_end()
.
countrypops |> dplyr::select(-contains("code")) |> dplyr::filter(country_name == "Benin") |> dplyr::slice_tail(n = 5) |> gt() |> cols_move_to_end(columns = year)
We can also move multiple columns at a time. With the same
countrypops
-based table, let's move both the year
and country_name
columns to the end of the column series.
countrypops |> dplyr::select(-contains("code")) |> dplyr::filter(country_name == "Benin") |> dplyr::slice_tail(n = 5) |> gt() |> cols_move_to_end(columns = c(year, country_name))
Function ID
5-11
Function Introduced
v0.2.0.5
(March 31, 2020)
See Also
Other column modification functions:
cols_add()
,
cols_align()
,
cols_align_decimal()
,
cols_hide()
,
cols_label()
,
cols_label_with()
,
cols_merge()
,
cols_merge_n_pct()
,
cols_merge_range()
,
cols_merge_uncert()
,
cols_move()
,
cols_move_to_start()
,
cols_nanoplot()
,
cols_unhide()
,
cols_units()
,
cols_width()