Learn R Programming

ProfileGLMM (version 1.1.0)

encodeCat: One-Hot Encodes Factor Variables (FIRST Level as Reference)

Description

This function takes a dataframe, identifies all columns of class factor, and converts them into **dummy variables** using one-hot encoding via stats::model.matrix. For each factor, the function explicitly removes the first dummy variable generated, effectively making the **first level** of the factor the **reference level** (omitted category). Non-factor columns are retained as is.

Usage

encodeCat(dataframe)

Value

A data.frame where:

  • All original non-factor columns are present.

  • All original factor columns are replaced by a set of binary (0/1) dummy variables. The first level of the factor is excluded from the generated dummies, making the last level the reference.

Arguments

dataframe

A data.frame containing the data to be processed, which may include factor variables.

Examples

Run this code
data("exposure_data")
exp_data = exposure_data$df
covList = {}
covList$FE = c('X')
XFE = encodeCat(exp_data[,covList$FE, drop = FALSE])

Run the code above in your browser using DataLab