powered by
Given a matrix or data.frame containing character/factors, this function performs one-hot-encoding.
dummy_data(X, lev = NULL)
X (class: "matrix") after performing one-hot-encoding.
A matrix, or a data.frame containing factors. (If the columns are of any other class, they will be coerced into factors anyway).
(optional) A vector with the categories ("levels") of each factor.
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