The cols_move_to_start() function

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 start of the column series with cols_move_to_start().

countrypops |>
  dplyr::select(-contains("code")) |>
  dplyr::filter(
    country_name == "Fiji",
    year %in% 2017:2021
  ) |>
  gt() |>
  cols_move_to_start(columns = year)
year country_name population
2017 Fiji 919019
2018 Fiji 918996
2019 Fiji 918465
2020 Fiji 920422
2021 Fiji 924610

We can also move multiple columns at a time. With the same countrypops-based table, let’s move both the year and population columns to the start of the column series.

countrypops |>
  dplyr::select(-contains("code")) |>
  dplyr::filter(
    country_name == "Fiji",
    year %in% 2017:2021
  ) |>
  gt() |>
  cols_move_to_start(columns = c(year, population))
year population country_name
2017 919019 Fiji
2018 918996 Fiji
2019 918465 Fiji
2020 920422 Fiji
2021 924610 Fiji