conv_factor: Convert factor columns

View source: R/utils-conv.R

conv_factorR Documentation

Convert factor columns

Description

Convert factor columns

Usage

conv_factor(df, factor_cols)

Arguments

df

a data table in which to convert factor columns

factor_cols

columns to be converted to a factor

Details

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).

Value

a data table

Examples


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


dylanrussellmd/nsqipr documentation built on Oct. 13, 2023, 11:01 a.m.