Learn R Programming

rtables (version 0.5.1)

split_cols_by_multivar: Associate Multiple Variables with Columns

Description

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

Usage

split_cols_by_multivar(
  lyt,
  vars,
  split_fun = NULL,
  varlabels = vars,
  varnames = NULL,
  nested = TRUE
)

Value

A PreDataTableLayouts object suitable for passing to further layouting functions, and to build_table.

Arguments

lyt

layout object pre-data used for tabulation

vars

character vector. Multiple variable names.

split_fun

function/NULL. custom splitting function See custom_split_funs

varlabels

character vector. Labels for vars

varnames

character vector. Names for vars which will appear in pathing. When vars are all unique this will be the variable names. If not, these will be variable names with suffixes as necessary to enforce uniqueness.

nested

boolean. Should this layout instruction be applied within the existing layout structure if possible (TRUE, the default) or as a new top-level element (`FALSE). Ignored if it would nest a split underneath analyses, which is not allowed.

Author

Gabriel Becker

See Also

analyze_colvars

Examples

Run this code

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"))

l <- 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)

l

build_table(l, ANL)

Run the code above in your browser using DataLab