Learn R Programming

dataPreparation (version 0.4.3)

generateFromFactor: Recode factor

Description

Recode factors into 3 new columns:

  • was the value not NA, "NA", "",

  • how often this value occures,

  • the order of the value (ex: M/F => 2/1 because F comes before M in alphabet).

Usage

generateFromFactor(dataSet, cols = "auto", verbose = TRUE, drop = FALSE, ...)

Arguments

dataSet

Matrix, data.frame or data.table

cols

list of character column(s) name(s) of dataSet to transform. To transform all factors, set it to "auto". (character, default to "auto")

verbose

Should the function log (logical, default to TRUE)

drop

Should cols be dropped after generation (logical, default to FALSE)

...

Other arguments such as name_separator to separate words in new columns names (character, default to ".")

Value

dataSet with new columns. dataSet is edited by reference.

Examples

Run this code
# NOT RUN {
# Load data set
data(messy_adult)

# transform column "type_employer"
messy_adult <- generateFromFactor(messy_adult, cols = "type_employer")
head(messy_adult)

# To transform all factor columns:
messy_adult <- generateFromFactor(messy_adult, cols = "auto")
# }

Run the code above in your browser using DataLab