Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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.


hardhat

Construct Modeling Packages

v0.1.5
MIT + file LICENSE
Authors
Davis Vaughan [aut, cre], Max Kuhn [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.