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.