Learn R Programming

gt (version 0.7.0)

cols_move_to_end: 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)

Value

An object of class gt_tbl.

Arguments

data

A table object that is created using the gt() function.

columns

The column names to move to the right-most side of the table. The order in which columns are provided will be preserved (as is the case with the remaining columns).

Examples

Use countrypops to create a gt table. With the remaining columns, move the year column to the end of the column series with the cols_move_to_end() function.

countrypops %>%
  dplyr::select(-contains("code")) %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_move_to_end(columns = year)

This image of a table was generated from the first code example in the `cols_move_to_end()` help file.

Use countrypops to create a gt table. With the remaining columns, move year and country_name to the end of the column series.

countrypops %>%
  dplyr::select(-contains("code")) %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_move_to_end(columns = c(year, country_name))

This image of a table was generated from the second code example in the `cols_move_to_end()` help file.

Function ID

4-5

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, the cols_move_to_start() function should be used. More control is offered with the cols_move() function, where columns could be placed after a specific column.

See Also

Other column modification functions: cols_align(), cols_hide(), cols_label(), cols_merge_n_pct(), cols_merge_range(), cols_merge_uncert(), cols_merge(), cols_move_to_start(), cols_move(), cols_unhide(), cols_width()