conv_factor | R Documentation |
Convert factor columns
conv_factor(df, factor_cols)
df |
a data table in which to convert factor columns |
factor_cols |
columns to be converted to a factor |
This function modifies by reference.
This function checks for which columns to factor by comparing against a character vector called factor_cols
.
The function then fetches a variable from the calling environment with the same name as the column being converted to a factor.
This variable should reference a named list specifying how to rename the levels (see %^%
for further details).
a data table
x <- data.table::data.table(foods = c("apple","banana","cherry","steak","chicken","pork"),
drinks = c("milk","water","oj","beer","vodka","rum"))
foods <- list(fruit = c("apple", "banana", "cherry"), meat = c("steak","chicken","pork"))
drinks <- list(`non-alcoholic` = c("milk","water","oj"), alcoholic = c("beer","vodka","rum"))
factor_cols <- c("foods", "drinks")
nsqipr:::conv_factor(x, factor_cols)
x
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.