View source: R/colby_constructors.R
split_cols_by_multivar | R Documentation |
In some cases, the variable to be ultimately analyzed is most naturally
defined on a column, not a row basis. When we need columns to reflect
different variables entirely, rather than different levels of a single
variable, we use split_cols_by_multivar
split_cols_by_multivar(
lyt,
vars,
split_fun = NULL,
varlabels = vars,
varnames = NULL,
nested = TRUE,
extra_args = list()
)
lyt |
layout object pre-data used for tabulation |
vars |
character vector. Multiple variable names. |
split_fun |
function/NULL. custom splitting function See
|
varlabels |
character vector. Labels for |
varnames |
character vector. Names for |
nested |
boolean. Should this layout instruction be applied within the
existing layout structure if possible ( |
extra_args |
list. Extra arguments to be passed to the tabulation function. Element position in the list corresponds to the children of this split. Named elements in the child-specific lists are ignored if they do not match a formal argument of the tabulation function. |
A PreDataTableLayouts
object suitable for passing to further
layouting functions, and to build_table
.
Gabriel Becker
analyze_colvars()
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) in_rows(mean = mean(x), .formats = "xx.x"),
function(x) in_rows("# x > 5" = sum(x > .5), .formats = "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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.