dm <- DM
dm$colspan_trt <- factor(
ifelse(dm$ARM == "B: Placebo", " ", "Active Study Agent"),
levels = c("Active Study Agent", " ")
)
colspan_trt_map <- create_colspan_map(
dm,
non_active_grp = "B: Placebo",
non_active_grp_span_lbl = " ",
active_grp_span_lbl = "Active Study Agent",
colspan_var = "colspan_trt",
trt_var = "ARM"
)
standard_afun <- function(x, .ref_group, .in_ref_col) {
in_rows(
"Difference of Averages" = non_ref_rcell(
mean(x) - mean(.ref_group),
is_ref = .in_ref_col,
format = "xx.xx"
)
)
}
result_afun <- function(x, ref_path, .spl_context, .var) {
ref <- get_ref_info(ref_path, .spl_context, .var)
standard_afun(x, .ref_group = ref$ref_group, .in_ref_col = ref$in_ref_col)
}
ref_path <- c("colspan_trt", " ", "ARM", "B: Placebo")
lyt <- basic_table() |>
split_cols_by(
"colspan_trt",
split_fun = trim_levels_to_map(map = colspan_trt_map)
) |>
split_cols_by("ARM") |>
analyze(
"AGE",
extra_args = list(ref_path = ref_path),
afun = result_afun
)
build_table(lyt, dm)
Run the code above in your browser using DataLab