extract_summary: Extract a summary list from a *gt* object

Description Usage Arguments Value Figures Function ID See Also Examples

View source: R/export.R

Description

Get a list of summary row data frames from a gt_tbl object where summary rows were added via the summary_rows() function. The output data frames contain the groupname and rowname columns, whereby rowname contains descriptive stub labels for the summary rows.

Usage

1

Arguments

data

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

Value

A list of data frames containing summary data.

Figures

Function ID

13-5

See Also

Other Export Functions: as_latex(), as_raw_html(), as_rtf(), gtsave()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Use `sp500` to create a gt table with
# row groups; create summary rows by row
# group (`min`, `max`, `avg`) and then
# extract the summary rows as a list
# object
summary_extracted <-
  sp500 %>%
  dplyr::filter(
    date >= "2015-01-05" &
      date <="2015-01-30"
  ) %>%
  dplyr::arrange(date) %>%
  dplyr::mutate(
    week = paste0(
      "W", strftime(date, format = "%V"))
  ) %>%
  dplyr::select(-adj_close, -volume) %>%
  gt(
    rowname_col = "date",
    groupname_col = "week"
  ) %>%
  summary_rows(
    groups = TRUE,
    columns = vars(open, high, low, close),
    fns = list(
      min = ~min(.),
      max = ~max(.),
      avg = ~mean(.)),
    formatter = fmt_number,
    use_seps = FALSE
  ) %>%
  extract_summary()

# Use the summary list to make a new
# gt table; the key thing is to use
# `dplyr::bind_rows()` and then pass the
# tibble to `gt()` (the `groupname` and
# `rowname` magic column names create
# row groups and a stub)
tab_1 <-
  summary_extracted %>%
  unlist(recursive = FALSE) %>%
  dplyr::bind_rows() %>%
  gt()

gt documentation built on Aug. 6, 2020, 1:07 a.m.