Returns the formatted table as a plain data frame, the counterpart of
gtsummary::as_tibble(). Formatting functions, merged columns and hidden
columns are applied; bold and italic cells are wrapped in markdown markers
(__bold__, _italic_); and the column names are the header labels.
Usage
# S3 method for class 'ltsummary'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
...,
col_labels = TRUE,
fmt_missing = FALSE
)Arguments
- x
(
ltsummary)
An ltsummary object.- row.names, optional
Not used.
- ...
Not used.
- col_labels
(
scalar logical)
Whether to name the columns with their header labels. Default isTRUE;FALSEkeeps the column names ofx$table_body.- fmt_missing
(
scalar logical)
Whether to replace missing values with the symbols set bymodify_missing_symbol(). Default isFALSE, which leaves themNA.
See also
Other output:
as_lt(),
inline_text(),
print.ltsummary()
Examples
tbl <- trial |>
tbl_summary(by = trt, include = c(age, grade, response)) |>
bold_labels()
# Example 1 ----------------------------------
as.data.frame(tbl)
#> **Characteristic** **Drug A** \nN = 95 **Drug B** \nN = 105
#> 1 __Age__ 59 (51, 66) 62 (54, 71)
#> 2 Unknown 4 7
#> 3 __Grade__ <NA> <NA>
#> 4 I 25 (26%) 37 (35%)
#> 5 II 40 (42%) 43 (41%)
#> 6 III 30 (32%) 25 (24%)
#> 7 __Tumor Response__ 22 (24%) 24 (24%)
#> 8 Unknown 2 5
# Example 2 ----------------------------------
# without the header labels, and with the missing-value symbols
tbl |>
modify_missing_symbol("n/a", columns = all_stat_cols(), rows = row_type == "label") |>
as.data.frame(col_labels = FALSE, fmt_missing = TRUE)
#> label stat_1 stat_2
#> 1 __Age__ 59 (51, 66) 62 (54, 71)
#> 2 Unknown 4 7
#> 3 __Grade__ n/a n/a
#> 4 I 25 (26%) 37 (35%)
#> 5 II 40 (42%) 43 (41%)
#> 6 III 30 (32%) 25 (24%)
#> 7 __Tumor Response__ 22 (24%) 24 (24%)
#> 8 Unknown 2 5