ohe.df: One-hot encodes all categorical variables in a data.frame

View source: R/ohe.df.R

ohe.dfR Documentation

One-hot encodes all categorical variables in a data.frame

Description

One-hot encodes all categorical variables in a data.frame

Usage

ohe.df(df, drop_ref = TRUE)

Arguments

df

A data.frame that can contain columns of any variable type.

drop_ref

Logical, default = TRUE. Will return x - 1 columns for x unique categories. Choose FALSE to return x columns.

Value

A data.frame of all columns of class factor returned as one-hot encoded. All other column types are returned untouched.

Examples

df <- data.frame(lets = rep(letters[1:3], 3), LETS = rep(LETTERS[1:3], 3), x = rnorm(9))
ohe.df(df)

gweissman/gmish documentation built on Feb. 21, 2025, 1:20 a.m.