utils_split_funs {tern} | R Documentation |
Custom split functions
Description
Collection of useful functions that are expanding on the core list of functions
provided by rtables
. See rtables::custom_split_funs and rtables::make_split_fun()
for more information on how to make a custom split function. All these functions
work with rtables::split_rows_by()
argument split_fun
to modify the way the split
happens. For other split functions, consider consulting rtables::split_funcs
.
Usage
ref_group_position(position = "first")
level_order(order)
Arguments
position |
( |
order |
( |
Value
-
ref_group_position()
returns an utility function that puts the reference group as first, last or at a certain position and needs to be assigned tosplit_fun
.
-
level_order()
returns an utility function that changes the original levels' order, depending on inputorder
and split levels.
Functions
-
ref_group_position()
: Split function to place reference group facet at a specific position during post-processing stage. -
level_order()
: Split function to change level order based on aninteger
vector or acharacter
vector that represent the split variable's factor levels.
See Also
Examples
library(dplyr)
dat <- data.frame(
x = factor(letters[1:5], levels = letters[5:1]),
y = 1:5
)
# With rtables layout functions
basic_table() %>%
split_cols_by("x", ref_group = "c", split_fun = ref_group_position("last")) %>%
analyze("y") %>%
build_table(dat)
# With tern layout funcitons
adtte_f <- tern_ex_adtte %>%
filter(PARAMCD == "OS") %>%
mutate(
AVAL = day2month(AVAL),
is_event = CNSR == 0
)
basic_table() %>%
split_cols_by(var = "ARMCD", ref_group = "ARM B", split_fun = ref_group_position("first")) %>%
add_colcounts() %>%
surv_time(
vars = "AVAL",
var_labels = "Survival Time (Months)",
is_event = "is_event",
) %>%
build_table(df = adtte_f)
basic_table() %>%
split_cols_by(var = "ARMCD", ref_group = "ARM B", split_fun = ref_group_position(2)) %>%
add_colcounts() %>%
surv_time(
vars = "AVAL",
var_labels = "Survival Time (Months)",
is_event = "is_event",
) %>%
build_table(df = adtte_f)
# level_order --------
# Even if default would bring ref_group first, the original order puts it last
basic_table() %>%
split_cols_by("Species", split_fun = level_order(c(1, 3, 2))) %>%
analyze("Sepal.Length") %>%
build_table(iris)
# character vector
new_order <- level_order(levels(iris$Species)[c(1, 3, 2)])
basic_table() %>%
split_cols_by("Species", ref_group = "virginica", split_fun = new_order) %>%
analyze("Sepal.Length") %>%
build_table(iris)