Summary Table
summary_table.Rd
summary_table()
summarises clinical variables into a report table using
data.table
as backend.
Usage
summary_table(
dt,
target,
treat,
target_name = target,
indent = nbsp(n = 4L),
.total_dt = dt,
pct_dec = 1,
treat_order = NULL,
skip_absent = TRUE
)
Arguments
- dt
A
data.frame
containing, at least, the variables indicated intarget
andtreat
.- target
Target variable passed as a string for which summary statistics are to be calculated.
- treat
A string indicating the grouping variable, e.g. the variable specifying the treatment population.
- target_name
Heading for the target variable as a string. Defaults to
target
.- indent
A string to be used as indentation of summary statistics labels. Defaults to four HTML non-breaking spaces (
).- .total_dt
Separate table from
dt
from which to derive total counts per group.- pct_dec
Decimal places for reported figures.
- treat_order
Customise the column order of the output table.
- skip_absent
Whether to ignore variables passed in
treat_order
that are absent fromdt
. Default isTRUE
;FALSE
will throw an error in case there are missing variables.
Value
A data.table
of summary statistics. The format depends on the
type of the target
variable:
If the
target
variable is categorical, i.e. typecharacter
,factor
orlogical
then the output is that ofcalc_counts()
.If the
target
variable is numeric, then the output is that ofcalc_desc()
.
Examples
dmg_vars <- c("AGE", "RACE", "ETHNIC")
dmg_var_lbls <- c("Age (yr)", "Race", "Ethnicity")
# Demographics table (DMT01)
summary_table(
adsl,
target = dmg_vars,
treat = 'ARM',
target_name = dmg_var_lbls
)
#> stats
#> <char>
#> 1: Age (yr)
#> 2: n
#> 3: Mean (SD)
#> 4: Median
#> 5: Min, Max
#> 6: Missing
#> 7: Race
#> 8: AMERICAN INDIAN OR ALASKA NATIVE
#> 9: ASIAN
#> 10: BLACK OR AFRICAN AMERICAN
#> 11: MULTIPLE
#> 12: NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER
#> 13: OTHER
#> 14: UNKNOWN
#> 15: WHITE
#> 16: Ethnicity
#> 17: HISPANIC OR LATINO
#> 18: NOT HISPANIC OR LATINO
#> 19: NOT REPORTED
#> 20: UNKNOWN
#> stats
#> A: Drug X B: Placebo C: Combination
#> <char> <char> <char>
#> 1:
#> 2: 134 134 132
#> 3: 33.8 (6.6) 35.4 (7.9) 35.4 (7.7)
#> 4: 33 35 35
#> 5: 21.0, 50.0 21.0, 62.0 20.0, 69.0
#> 6: 0 0 0
#> 7:
#> 8: 8 (6.0%) 11 (8.2%) 6 (4.5%)
#> 9: 68 (50.7%) 67 (50.0%) 73 (55.3%)
#> 10: 31 (23.1%) 28 (20.9%) 32 (24.2%)
#> 11: 0 1 (0.7%) 0
#> 12: 0 1 (0.7%) 0
#> 13: 0 0 0
#> 14: 0 0 0
#> 15: 27 (20.1%) 26 (19.4%) 21 (15.9%)
#> 16:
#> 17: 15 (11.2%) 18 (13.4%) 15 (11.4%)
#> 18: 104 (77.6%) 103 (76.9%) 101 (76.5%)
#> 19: 6 (4.5%) 10 (7.5%) 11 (8.3%)
#> 20: 9 (6.7%) 3 (2.2%) 5 (3.8%)
#> A: Drug X B: Placebo C: Combination
# Demographics table (DMT01) with continuous variable (e.g., BMRKR1)
summary_table(
adsl,
target = c(dmg_vars, "BMRKR1"),
treat = 'ARM',
target_name = c(dmg_var_lbls, "Biomarker 1")
)
#> stats
#> <char>
#> 1: Age (yr)
#> 2: n
#> 3: Mean (SD)
#> 4: Median
#> 5: Min, Max
#> 6: Missing
#> 7: Race
#> 8: AMERICAN INDIAN OR ALASKA NATIVE
#> 9: ASIAN
#> 10: BLACK OR AFRICAN AMERICAN
#> 11: MULTIPLE
#> 12: NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER
#> 13: OTHER
#> 14: UNKNOWN
#> 15: WHITE
#> 16: Ethnicity
#> 17: HISPANIC OR LATINO
#> 18: NOT HISPANIC OR LATINO
#> 19: NOT REPORTED
#> 20: UNKNOWN
#> 21: Biomarker 1
#> 22: n
#> 23: Mean (SD)
#> 24: Median
#> 25: Min, Max
#> 26: Missing
#> stats
#> A: Drug X B: Placebo C: Combination
#> <char> <char> <char>
#> 1:
#> 2: 134 134 132
#> 3: 33.8 (6.6) 35.4 (7.9) 35.4 (7.7)
#> 4: 33 35 35
#> 5: 21.0, 50.0 21.0, 62.0 20.0, 69.0
#> 6: 0 0 0
#> 7:
#> 8: 8 (6.0%) 11 (8.2%) 6 (4.5%)
#> 9: 68 (50.7%) 67 (50.0%) 73 (55.3%)
#> 10: 31 (23.1%) 28 (20.9%) 32 (24.2%)
#> 11: 0 1 (0.7%) 0
#> 12: 0 1 (0.7%) 0
#> 13: 0 0 0
#> 14: 0 0 0
#> 15: 27 (20.1%) 26 (19.4%) 21 (15.9%)
#> 16:
#> 17: 15 (11.2%) 18 (13.4%) 15 (11.4%)
#> 18: 104 (77.6%) 103 (76.9%) 101 (76.5%)
#> 19: 6 (4.5%) 10 (7.5%) 11 (8.3%)
#> 20: 9 (6.7%) 3 (2.2%) 5 (3.8%)
#> 21:
#> 22: 134 134 132
#> 23: 6.0 (3.6) 5.7 (3.3) 5.6 (3.5)
#> 24: 5.4 4.8 4.6
#> 25: 0.4, 17.7 0.6, 14.2 0.2, 21.4
#> 26: 0 0 0
#> A: Drug X B: Placebo C: Combination