Learn R Programming

bigutilsr (version 0.3.11)

as_model_matrix: Transform a data frame

Description

Transform a data frame into a matrix using one hot encoding.

Usage

as_model_matrix(df, intercept = FALSE)

Value

A matrix.

Arguments

df

A data frame.

intercept

Whether to have a column with all 1s. Default is FALSE.

Examples

Run this code
mat <- as_model_matrix(iris)
str(mat)

Run the code above in your browser using DataLab