Factorize a column. This function is typically not called directly, but is called as part of the factorize_df function.
Usage
factorize_column(
x,
var_str,
vals_df,
variable_colname = "variable",
value_colname = "value",
value_label_colname = "value_label",
value_order_colname = "value",
extra_labels = NULL,
add_na = TRUE
)
Arguments
- x
A vector (or variable) to be 'factorized' or labeled. X is often a single variable or column within a dataframe.
- var_str
The name of the vector or variable to be factorized (e.g., "sample_segment").
- vals_df
A dataframe of variable labels (i.e., factor levels and labels) with the format as specified below.
- variable_colname
The name of the variable column in vals_df. Default is 'variable'.
- value_colname
The name of the value column in vals_df. Default is 'value',
- value_label_colname
The name of the value label column in vals_df. Default is 'value_label'
- value_order_colname
The name of the value order column in vals_df (can be the value column itself). Default is 'value'.
- extra_labels
Pass a vector of the names of other variables in the values dataframe to use when labeling. Common uses include missing values, universal values (e.g., "Total" or "Subtotal" row), or similar variables (e.g., "mode_1" to reuse the mode_1 labels for mode_2). Default is NULL.
- add_na
TRUE or FALSE setting for whether to add NA as an explicit level in the factor. Default setting of TRUE.
Value
A 'factorized' version of the vector it was passed (i.e., a factor). This is returned invisibly.