Learn R Programming

hardhat (version 0.2.0)

contr_one_hot: Contrast function for one-hot encodings

Description

This contrast function produces a model matrix that has indicator columns for each level of each factor.

Usage

contr_one_hot(n, contrasts = TRUE, sparse = FALSE)

Arguments

n

A vector of character factor levels or the number of unique levels.

contrasts

This argument is for backwards compatibility and only the default of TRUE is supported.

sparse

This argument is for backwards compatibility and only the default of FALSE is supported.

Value

A diagonal matrix that is n-by-n.