gt (version 0.1.0)

tab_row_group: Add a row group to a gt table

Description

Create a row group with a collection of rows. This requires specification of the rows to be included, either by supplying row labels, row indices, or through use of a select helper function like starts_with().

Usage

tab_row_group(data, group = NULL, rows = NULL, others = NULL)

Arguments

data

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

group

The name of the row group. This text will also serve as the row group label.

rows

The rows to be made components of the row group. Can either be a vector of row captions provided in c(), a vector of row indices, or a helper function focused on selections. The select helper functions are: starts_with(), ends_with(), contains(), matches(), one_of(), and everything().

others

An option to set a default row group label for any rows not formally placed in a row group named by group in any call of tab_row_group(). A separate call to tab_row_group() with only a value to others is possible and makes explicit that the call is meant to provide a default row group label. If this is not set and there are rows that haven't been placed into a row group (where one or more row groups already exist), those rows will be automatically placed into a row group without a label.

Value

An object of class gt_tbl.

Figures

Function ID

2-4

See Also

Other Create or Modify Parts: tab_footnote(), tab_header(), tab_options(), tab_source_note(), tab_spanner_delim(), tab_spanner(), tab_stubhead(), tab_style()

Examples

Run this code
# NOT RUN {
# Use `gtcars` to create a gt table and
# add two row groups with the labels:
# `numbered` and `NA` (a group without
# a title, or, the rest)
tab_1 <-
  gtcars %>%
  dplyr::select(model, year, hp, trq) %>%
  dplyr::slice(1:8) %>%
  gt(rowname_col = "model") %>%
  tab_row_group(
    group = "numbered",
    rows = matches("^[0-9]")
  )

# Use `gtcars` to create a gt table;
# add two row groups with the labels
# `powerful` and `super powerful`: the
# distinction being `hp` lesser or
# greater than `600`
tab_2 <-
  gtcars %>%
  dplyr::select(model, year, hp, trq) %>%
  dplyr::slice(1:8) %>%
  gt(rowname_col = "model") %>%
  tab_row_group(
    group = "powerful",
    rows = hp <= 600
  ) %>%
  tab_row_group(
    group = "super powerful",
    rows = hp > 600
  )

# }

Run the code above in your browser using DataLab