Add as many binaries than input columns, taking the value 1 if value in each column is inside a set a values
add_binaries_from_set.Rd
Useful to create a set of dummy variables from a set of categorical variables if they are in a defined set of choices For HESPER package, can be used to create binaries for all HESPER items select one columns, to either record if it's a serious problem, undefined, serious problem with subset Additionnal argument can be used to add a suffix to the column names of the binary created
Usage
add_binaries_from_set(
df,
vars,
vals_0,
vals_1,
vals_na = NULL,
default_val = NULL,
suffix = NULL,
sep = "."
)
Arguments
- df
A df.table or df.frame: The df to be processed.
- suffix
A character vector: The suffix to be added to the added binary vars. If NULL, vars are replaced by binary vars.
- sep
A character vector: separator used to add name suffix to original column names
- cols_character
A character vector: The name of the columns that will be used to create binary columns.
- value_1
A character vector: Set of values for which binary columns will be populated with 1 if
cols_character
is inside this set.- value_0
A character vector: Set of values for which binary columns will be populated with 0 if
cols_character
is inside this set.- value_na
A character vector: Set of values for which binary columns will be populated with NA if
cols_character
is inside this set.- value_default
A character vector: Set of values for which binary columns will be populated with otherwise. Will be overriden with 0 if value_0 = NULL and with NA if value_na = NULL