Learn R Programming

kerntools (version 1.2.0)

dummy_data: Convert categorical data to dummies.

Description

Given a matrix or data.frame containing character/factors, this function performs one-hot-encoding.

Usage

dummy_data(X, lev = NULL)

Value

X (class: "matrix") after performing one-hot-encoding.

Arguments

X

A matrix, or a data.frame containing factors. (If the columns are of any other class, they will be coerced into factors anyway).

lev

(optional) A vector with the categories ("levels") of each factor.

Examples

Run this code
summary(CO2)
CO2_dummy <- dummy_data(CO2[,1:3],lev=dummy_var(CO2[,1:3]))
CO2_dummy[1:10,1:5]

Run the code above in your browser using DataLab