The cols_merge_range() function

Let’s use a subset of the gtcars dataset to create a gt table, keeping only the model, mpg_c, and mpg_h columns. Merge the "mpg*" columns together as a single range column (which is labeled as MPG, in italics) using the cols_merge_range() function. After the merging process, the column label for the mpg_c column is updated with cols_label() to better describe the content.

gtcars |>
  dplyr::select(model, starts_with("mpg")) |>
  dplyr::slice(1:8) |>
  gt() |>
  cols_merge_range(
    col_begin = mpg_c,
    col_end = mpg_h
  ) |>
  cols_label(mpg_c = md("*MPG*"))
model MPG
GT 11–18
458 Speciale 13–17
458 Spider 13–17
458 Italia 13–17
488 GTB 15–22
California 16–23
GTC4Lusso 12–17
FF 11–16