View source: R/colby_constructors.R
| analyze_colvars | R Documentation |
Generate rows analyzing different variables across columns
analyze_colvars(
lyt,
afun,
parent_name = get_acolvar_name(lyt),
format = NULL,
na_str = NA_character_,
nested = TRUE,
at_sibling = NULL,
extra_args = list(),
indent_mod = 0L,
inclNAs = FALSE
)
lyt |
( |
afun |
( |
parent_name |
( |
format |
( |
na_str |
( |
nested |
( |
at_sibling |
( |
extra_args |
( |
indent_mod |
( |
inclNAs |
( |
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
split_cols_by_multivar()
library(dplyr)
ANL <- DM |> mutate(value = rnorm(n()), pctdiff = runif(n()))
## toy example where we take the mean of the first variable and the
## count of >.5 for the second.
colfuns <- list(
function(x) rcell(mean(x), format = "xx.x"),
function(x) rcell(sum(x > .5), format = "xx")
)
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by_multivar(c("value", "pctdiff")) |>
split_rows_by("RACE",
split_label = "ethnicity",
split_fun = drop_split_levels
) |>
summarize_row_groups() |>
analyze_colvars(afun = colfuns)
lyt
tbl <- build_table(lyt, ANL)
tbl
lyt2 <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by_multivar(c("value", "pctdiff"),
varlabels = c("Measurement", "Pct Diff")
) |>
split_rows_by("RACE",
split_label = "ethnicity",
split_fun = drop_split_levels
) |>
summarize_row_groups() |>
analyze_colvars(afun = mean, format = "xx.xx")
tbl2 <- build_table(lyt2, ANL)
tbl2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.