Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cols_move_to_start

Move one or more columns to the start


Description

We can easily move set of columns to the beginning of the column series and we only need to specify which columns. It's possible to do this upstream of gt, however, it is easier with this function and it presents less possibility for error. The ordering of the columns that are moved to the start is preserved (same with the ordering of all other columns in the table).

Usage

cols_move_to_start(data, columns)

Arguments

data

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

columns

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

Details

The columns supplied in columns must all exist in the table. If you need to place one or columns at the end of the column series, the cols_move_to_end() function should be used. More control is offered with the cols_move() function, where columns could be placed after a specific column.

Value

An object of class gt_tbl.

Figures

Function ID

4-4

See Also

Examples

# Use `countrypops` to create a gt table;
# With the remaining columns, move the
# `year` column to the start
tab_1 <-
  countrypops %>%
  dplyr::select(-contains("code")) %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_move_to_start(
    columns = vars(year)
  )

# Use `countrypops` to create a gt table;
# With the remaining columns, move `year`
# and `population` to the start
tab_2 <-
  countrypops %>%
  dplyr::select(-contains("code")) %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_move_to_start(
    columns = vars(year, population)
  )

gt

Easily Create Presentation-Ready Display Tables

v0.2.2
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>), Joe Cheng [aut], Barret Schloerke [aut] (<https://orcid.org/0000-0001-9986-114X>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.