matrix.one_hot: Creates a one-hot encoded matrix.

View source: R/matrix.R

matrix.one_hotR Documentation

Creates a one-hot encoded matrix.

Description

Creates a one-hot encoded matrix.

Usage

matrix.one_hot(mat, levels = NULL, n_threads = 1)

Arguments

mat

A dense matrix, which can include factors with levels coded as non-negative integers.

levels

Number of levels for each of the columns of mat, with 1 representing a quantitative feature. A factor with K levels should be represented by the numbers 0,1,...,K-1.

n_threads

Number of threads.

Value

One-hot encoded matrix. All the factor columns, with levels>1, are replaced by a collection of one-hot encoded versions (dummy matrices). The resulting matrix has sum(levels) columns. The object is an S4 class with methods for efficient computation by adelie. Note that some of the arguments are transformed to C++ base 0 for internal use, and if the object is examined, it will reflect that.

Author(s)

James Yang, Trevor Hastie, and Balasubramanian Narasimhan
Maintainer: Trevor Hastie hastie@stanford.edu

Examples

n <- 100
p <- 20
mat <- matrix(rnorm(n * p), n, p)
out <- matrix.one_hot(mat)

adelie documentation built on Sept. 11, 2024, 6:36 p.m.