enw_one_hot_encode_feature: One-hot encode a variable and column-bind it to the original...

View source: R/model-design-tools.R

enw_one_hot_encode_featureR Documentation

One-hot encode a variable and column-bind it to the original data.table

Description

This function takes a data.frame and a categorical variable, performs one-hot encoding, and column-binds the encoded variables back to the data.frame.

Usage

enw_one_hot_encode_feature(metaobs, feature, contrasts = FALSE)

Arguments

metaobs

A data.frame containing the data to be encoded.

feature

The name of the categorical variable to one-hot encode as a character string.

contrasts

Logical. If TRUE, create one-hot encoded variables with contrasts; if FALSE, create them without contrasts. Defaults to FALSE.

See Also

Functions used to formulate models enw_add_cumulative_membership(), enw_add_pooling_effect(), enw_design(), enw_effects_metadata()

Examples

metaobs <- data.frame(week = 1:2)
enw_one_hot_encode_feature(metaobs, "week")
enw_one_hot_encode_feature(metaobs, "week", contrasts = TRUE)

metaobs <- data.frame(week = 1:6)
enw_one_hot_encode_feature(metaobs, "week")
enw_one_hot_encode_feature(metaobs, "week", contrasts = TRUE)

seabbs/epinowcast documentation built on Sept. 20, 2024, 2:39 a.m.