Learn R Programming

lares (version 4.8.4)

ohe_commas: One Hot Encoding for a Vector with Comma Separated Values

Description

This function lets the user do one hot encoding on a variable with comma separated values

Usage

ohe_commas(df, variables, sep = ",", noval = "NoVal")

Arguments

df

Dataframe. May contain one or more columns with comma separated values which will be separated as one hot encoding

variables

Character. Which variables should split into new columns?

sep

Character. Which regular expression separates the elements?

noval

Character. No value text

See Also

Other Data Wrangling: balance_data(), categ_reducer(), cleanText(), date_cuts(), date_feats(), dateformat(), formatNum(), formatTime(), holidays(), impute(), left(), normalize(), numericalonly(), ohse(), rbind_full(), removenacols(), removenarows(), replaceall(), right(), textFeats(), textTokenizer(), vector2text(), year_month(), year_week()

Examples

Run this code
# NOT RUN {
df <- data.frame(id = c(1:5),
                 x = c("AA, D", "AA,B", "B,  D", "A,D,B", NA),
                 z = c("AA+BB+AA", "AA", "BB,  AA", NA, "BB+AA"))
ohe_commas(df, "x")
ohe_commas(df, c("x", "z"), sep = "\\+|,")
# }

Run the code above in your browser using DataLab