Learn R Programming

rtables (version 0.3.8)

remove_split_levels: Split functions

Description

Split functions

Usage

remove_split_levels(excl)

keep_split_levels(only, reorder = TRUE)

drop_split_levels(df, spl, vals = NULL, labels = NULL, trim = FALSE)

drop_and_remove_levels(excl)

reorder_split_levels(neworder, newlabels = neworder, drlevels = TRUE)

trim_levels_in_group(innervar)

trim_levels_by_map(innervar, outervar, map = NULL)

Arguments

excl

character. Levels to be excluded (they will not be reflected in the resulting table structure regardless of presence in the data).

only

character. Levels to retain (all others will be dropped).

reorder

logical(1). Should the order of only be used as the order of the children of the split. defaults to TRUE

df

dataset (data.frame or tibble)

spl

A Split object defining a partitioning or analysis/tabulation of the data.

vals

ANY. For internal use only.

labels

character. Labels to use for the remaining levels instead of the existing ones.

trim

logical(1). Should splits corresponding with 0 observations be kept when tabulating.

neworder

character. New order or factor levels.

newlabels

character. Labels for (new order of) factor levels

drlevels

logical(1). Should levels in the data which do not appear in neworder be dropped. Defaults to TRUE

innervar

character(1). Variable whose factor levels should be trimmed (e.g., empty levels dropped) separately within each grouping defined at this point in the structure

outervar

character(1). Parent split variable to trim innervar levels within. Must appear in map

map

data.frame. Data frame mapping outervar values to allowable innervar values. If no map exists a-priori, use

Value

a closure suitable for use as a splitting function (splfun) when creating a table layout

Examples

Run this code
# NOT RUN {
l <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("COUNTRY", split_fun = remove_split_levels(c("USA", "CAN", "CHE", "BRA"))) %>%
  analyze("AGE")

build_table(l, DM)

l <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("COUNTRY", split_fun = keep_split_levels(c("USA", "CAN", "BRA"))) %>%
  analyze("AGE")

build_table(l, DM)
l <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("SEX", split_fun = drop_split_levels) %>%
  analyze("AGE")

build_table(l, DM)
l <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) %>%
  analyze("AGE")

build_table(l, DM)
# }

Run the code above in your browser using DataLab