Computes one or more of the following statistics for use with
rtables::analyze():
"sum":sum(.var)"sum_unique":sum(.var)after keeping unique rows byid_var"ratio":sum(.var) / sum(denom_by)"ratio_unique": same ratio after keeping unique rows byid_var
Both .var and denom_by columns must be numeric (integer, double, or
logical coerced to numeric).
Usage
a_sum_ratio_j(
df,
.var,
.stats = "sum",
denom_by = NULL,
id_var = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL,
na_str = NULL,
...
)Arguments
- df
(
data.frame)
data set containing all analysis variables.- .var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.- .stats
(
character)
one or more of"sum","sum_unique","ratio","ratio_unique". Default:"sum".- denom_by
(
stringorNULL)
denominator column; required for"ratio"and"ratio_unique".- id_var
(
stringorNULL)
subject-id column for unique row selection; required for"sum_unique"and"ratio_unique".- .formats
(named
characterorlist)
formats for the statistics. See Details inanalyze_varsfor more information on the'auto'setting.- .labels
(named
character)
labels for the statistics (without indent).- .indent_mods
(named
integerorNULL)
indent modifiers for the row labels. Defaults toNULL(no modification).- na_str
(
characterorNULL)
string(s) used to replaceNAvalues in the formatted output. Defaults toNULL(no replacement).- ...
additional arguments for the lower level functions.
Examples
df <- data.frame(
USUBJID = c("S01", "S01", "S02", "S03"),
ARM = factor(c("A", "A", "A", "B")),
EVENTS = c(1, 1, 0, 1),
DAYS = c(10, 10, 20, 15)
)
# All 4 stats in a layout (S01 duplicate tests unique logic)
lyt <- basic_table() |>
split_cols_by("ARM") |>
analyze(
"EVENTS",
afun = a_sum_ratio_j,
extra_args = list(
.stats = c("sum", "sum_unique", "ratio", "ratio_unique"),
denom_by = "DAYS",
id_var = "USUBJID"
)
)
build_table(lyt, df)
#> A B
#> ————————————————————————————————————
#> Sum 2 1
#> Sum (unique) 1 1
#> Ratio 2 (5.0%) 1 (6.7%)
#> Ratio (unique) 1 (3.3%) 1 (6.7%)
