Learn R Programming

rtemis (version 1.4.3)

one_hot2factor: Convert one-hot encoded matrix to factor

Description

Convert one-hot encoded matrix to factor

Usage

one_hot2factor(x, labels = colnames(x))

Value

A factor.

Arguments

x

one-hot encoded matrix or data.frame.

labels

Character vector of level names.

Author

EDG

Details

If input has a single column, it will be converted to factor and returned

Examples

Run this code
x <- data.frame(matrix(FALSE, 10, 3))
colnames(x) <- c("Dx1", "Dx2", "Dx3")
x[["Dx1"]][1:3] <- x[["Dx2"]][4:6] <- x[["Dx3"]][7:10] <- TRUE
one_hot2factor(x)

Run the code above in your browser using DataLab