| split_cols_by_cuts | R Documentation |
Create columns (or row splits) based on values (such as quartiles) of var.
split_cols_by_cuts(
lyt,
var,
cuts,
cutlabels = NULL,
split_label = var,
nested = TRUE,
cumulative = FALSE,
show_colcounts = FALSE,
colcount_format = NULL
)
split_rows_by_cuts(
lyt,
var,
cuts,
cutlabels = NULL,
split_label = var,
parent_name = var,
format = NULL,
na_str = NA_character_,
nested = TRUE,
at_sibling = NULL,
cumulative = FALSE,
label_pos = if (!is.null(at_sibling)) "visible" else "default",
section_div = NA_character_
)
split_cols_by_cutfun(
lyt,
var,
cutfun = qtile_cuts,
cutlabelfun = function(x) NULL,
split_label = var,
nested = TRUE,
extra_args = list(),
cumulative = FALSE,
show_colcounts = FALSE,
colcount_format = NULL
)
split_cols_by_quartiles(
lyt,
var,
split_label = var,
nested = TRUE,
extra_args = list(),
cumulative = FALSE,
show_colcounts = FALSE,
colcount_format = NULL
)
split_rows_by_quartiles(
lyt,
var,
split_label = var,
parent_name = var,
format = NULL,
na_str = NA_character_,
nested = TRUE,
at_sibling = NULL,
child_labels = c("default", "visible", "hidden"),
extra_args = list(),
cumulative = FALSE,
indent_mod = 0L,
label_pos = if (!is.null(at_sibling)) "visible" else "default",
section_div = NA_character_
)
split_rows_by_cutfun(
lyt,
var,
cutfun = qtile_cuts,
cutlabelfun = function(x) NULL,
split_label = var,
parent_name = var,
format = NULL,
na_str = NA_character_,
nested = TRUE,
at_sibling = NULL,
child_labels = c("default", "visible", "hidden"),
extra_args = list(),
cumulative = FALSE,
indent_mod = 0L,
label_pos = if (!is.null(at_sibling)) "visible" else "default",
section_div = NA_character_
)
lyt |
( |
var |
( |
cuts |
( |
cutlabels |
( |
split_label |
( |
nested |
( |
cumulative |
( |
show_colcounts |
( |
colcount_format |
( |
parent_name |
( |
format |
( |
na_str |
( |
at_sibling |
( |
label_pos |
( |
section_div |
( |
cutfun |
( |
cutlabelfun |
( |
extra_args |
( |
child_labels |
( |
indent_mod |
( |
For dynamic cuts, the cut is transformed into a static cut by build_table() based on the full dataset,
before proceeding. Thus even when nested within another split in column/row space, the resulting split will reflect
the overall values (e.g., quartiles) in the dataset, NOT the values for subset it is nested under.
A PreDataTableLayouts object suitable for passing to further layouting functions, and to build_table().
When nested is TRUE, at_sibling allows you to set a nesting
anchor that your new split_rows_by* or analyze* directive
should be placed as a sibling to. The lookup for this anchor
occurs only in the currently active top-level nesting stack,
meaning the directives that have occurred since
the last split or analysis with nested == FALSE.
Furthermore, resolution occurs against the first element of each
arm of a branching point caused by any previous uses of
at_sibling but only descends into the last arm.
So for example if our previous layout was generated via:
lyt <- basic_table() |>
split_rows_by("SEX") |>
analyze("AGE") |>
split_rows_by("BMRKR2", nested = FALSE) |>
split_rows_by("RACE") |>
analyze("AGE") |>
split_rows_by("SEX", at_sibling = "RACE") |>
analyze("BMRKR1")
The eligible anchor points would be "BMRKR2", "RACE", "SEX"
and "BMRKR1". "AGE" is masked by the branching caused by
anchoring our SEX split on RACE.
Finally, while at_sibling does support de-duplication of
"<name>[i]" anchors, it does so within the set of available
anchors, which can be counter-intuitive. It is strongly suggested
that the parent_name and table_names argument(s) of
split_rows_by* and analyze be used to prevent the need for
this. at_sibling will resolve to table names overridden in this
manner.
Gabriel Becker
library(dplyr)
# split_cols_by_cuts
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by_cuts("AGE",
split_label = "Age",
cuts = c(0, 25, 35, 1000),
cutlabels = c("young", "medium", "old")
) |>
analyze(c("BMRKR2", "STRATA2")) |>
append_topleft("counts")
tbl <- build_table(lyt, ex_adsl)
tbl
# split_rows_by_cuts
lyt2 <- basic_table() |>
split_cols_by("ARM") |>
split_rows_by_cuts("AGE",
split_label = "Age",
cuts = c(0, 25, 35, 1000),
cutlabels = c("young", "medium", "old")
) |>
analyze(c("BMRKR2", "STRATA2")) |>
append_topleft("counts")
tbl2 <- build_table(lyt2, ex_adsl)
tbl2
# split_cols_by_quartiles
lyt3 <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by_quartiles("AGE", split_label = "Age") |>
analyze(c("BMRKR2", "STRATA2")) |>
append_topleft("counts")
tbl3 <- build_table(lyt3, ex_adsl)
tbl3
# split_rows_by_quartiles
lyt4 <- basic_table(show_colcounts = TRUE) |>
split_cols_by("ARM") |>
split_rows_by_quartiles("AGE", split_label = "Age") |>
analyze("BMRKR2") |>
append_topleft(c("Age Quartiles", " Counts BMRKR2"))
tbl4 <- build_table(lyt4, ex_adsl)
tbl4
# split_cols_by_cutfun
cutfun <- function(x) {
cutpoints <- c(
min(x),
mean(x),
max(x)
)
names(cutpoints) <- c("", "Younger", "Older")
cutpoints
}
lyt5 <- basic_table() |>
split_cols_by_cutfun("AGE", cutfun = cutfun) |>
analyze("SEX")
tbl5 <- build_table(lyt5, ex_adsl)
tbl5
# split_rows_by_cutfun
lyt6 <- basic_table() |>
split_cols_by("SEX") |>
split_rows_by_cutfun("AGE", cutfun = cutfun) |>
analyze("BMRKR2")
tbl6 <- build_table(lyt6, ex_adsl)
tbl6
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.