Learn R Programming

dataPreparation (version 1.1.1)

generate_from_character: Recode character

Description

Recode character into 3 new columns:

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

  • how often this value occurs,

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

Usage

generate_from_character(
  data_set,
  cols = "auto",
  verbose = TRUE,
  drop = FALSE,
  ...
)

Value

data_set with new columns. data_set is edited by reference.

Arguments

data_set

Matrix, data.frame or data.table

cols

List of character column(s) name(s) of data_set to transform. To transform all characters, 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 ".")

Examples

Run this code
# Load data set
data(tiny_messy_adult)
tiny_messy_adult <- un_factor(tiny_messy_adult, verbose = FALSE) # un factor ugly factors

# transform column "mail"
tiny_messy_adult <- generate_from_character(tiny_messy_adult, cols = "mail")
head(tiny_messy_adult)

# To transform all characters columns:
tiny_messy_adult <- generate_from_character(tiny_messy_adult, cols = "auto")

Run the code above in your browser using DataLab