action_to_onehot: Convert Action Column to One-Hot Encoding

View source: R/data_conversion.R

action_to_onehotR Documentation

Convert Action Column to One-Hot Encoding

Description

Convert a categorical Action column to one-hot (binary indicator) columns.

Usage

action_to_onehot(
  data,
  action_col = "Action",
  states = NULL,
  drop_action = TRUE,
  sort_states = FALSE,
  prefix = ""
)

Arguments

data

Data frame containing an action column.

action_col

Character. Name of the action column. Default: "Action".

states

Character vector or NULL. States to include as columns. If NULL, uses all unique values. Default: NULL.

drop_action

Logical. Remove the original action column. Default: TRUE.

sort_states

Logical. Sort state columns alphabetically. Default: FALSE.

prefix

Character. Prefix for state column names. Default: "".

Value

Data frame with one-hot encoded columns (0/1 integers).

Examples

long_data <- data.frame(
  Actor = rep(1:3, each = 4),
  Time = rep(1:4, 3),
  Action = sample(c("A", "B", "C"), 12, replace = TRUE)
)
onehot_data <- action_to_onehot(long_data)
head(onehot_data)


Nestimate documentation built on April 20, 2026, 5:06 p.m.