View source: R/data_conversion.R
| action_to_onehot | R Documentation |
Convert a categorical Action column to one-hot (binary indicator) columns.
action_to_onehot(
data,
action_col = "Action",
states = NULL,
drop_action = TRUE,
sort_states = FALSE,
prefix = ""
)
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: "". |
Data frame with one-hot encoded columns (0/1 integers).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.