Learn R Programming

teal.transform (version 0.6.0)

value_choices: Value labeling and filtering based on variable relationship

Description

[Stable]

Wrapper on choices_labeled to label variable values basing on other variable values.

Usage

value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

# S3 method for character value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

# S3 method for data.frame value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

Value

named character vector or delayed_data object.

Arguments

data

(data.frame, character) If data.frame, then data to extract labels from. If character, then name of the dataset to extract data from once available.

var_choices

(character, delayed_variable_choices) Choice of column names.

var_label

(character) vector with labels column names.

subset

(character or function) If character, vector with values to subset. If function, then this function is used to determine the possible columns (e.g. all factor columns). In this case, the function must take only single argument "data" and return a character vector.

See examples for more details.

sep

(character) separator used in case of multiple column names.

Examples

Run this code
ADRS <- teal.data::rADRS
value_choices(ADRS, "PARAMCD", "PARAM", subset = c("BESRSPI", "INVET"))
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"))
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"),
  subset = c("BESRSPI - ARM A", "INVET - ARM A", "OVRINV - ARM A")
)
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"), sep = " --- ")

# delayed version
value_choices("ADRS", c("PARAMCD", "ARMCD"), c("PARAM", "ARM"))

# functional subset
value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data) {
  levels(data$PARAMCD)[1:2]
})

Run the code above in your browser using DataLab