% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data_conversion.R
\name{prepare_onehot}
\alias{prepare_onehot}
\title{Import One-Hot Encoded Data into Sequence Format}
\usage{
prepare_onehot(
  data,
  cols,
  actor = NULL,
  session = NULL,
  interval = NULL,
  window_size = 3L,
  window_type = c("non-overlapping", "overlapping"),
  aggregate = FALSE
)
}
\arguments{
\item{data}{Data frame with binary (0/1) indicator columns.}

\item{cols}{Character vector. Names of the one-hot columns to use.}

\item{actor}{Character or NULL. Name of the actor/ID column. If NULL,
all rows are treated as a single sequence. Default: NULL.}

\item{session}{Character or NULL. Name of the session column for
sub-grouping within actors. Default: NULL.}

\item{interval}{Integer or NULL. Number of rows per time point in the
output. If NULL, all rows become a single time point group.
Default: NULL.}

\item{window_size}{Integer (>= 1). Number of consecutive rows to aggregate
into each window. Default: 3. Set \code{window_size = 1} for no
windowing (each row is its own time point).}

\item{window_type}{Character. \code{"non-overlapping"} (fixed, separate
windows) or \code{"overlapping"} (rolling, step = 1).
Default: \code{"non-overlapping"}.}

\item{aggregate}{Logical. If TRUE, aggregate within each window by
taking the first non-NA indicator per column. Default: FALSE.}
}
\value{
A data frame in wide format with columns named
\code{W{window}_T{time}} where each cell contains a state name or NA.
Attributes \code{windowed}, \code{window_size}, \code{window_span}
are set on the result.
}
\description{
Converts binary indicator (one-hot) data into the wide sequence format
expected by \code{\link{build_network}} and \code{tna::tna()}. Each binary
column represents a state; rows where the value is 1 are marked with the
column name. Supports optional windowed aggregation.

Simultaneous active states are preserved using the same window-span
representation as \code{tna::import_onehot()}: each input row/window is
expanded to one sequence slot per code and transition counting occurs between
windows, not between simultaneous states inside the same row.
}
\examples{
# Simple binary data
df <- data.frame(
  A = c(1, 0, 1, 0, 1),
  B = c(0, 1, 0, 1, 0),
  C = c(0, 0, 0, 0, 0)
)
seq_data <- prepare_onehot(df, cols = c("A", "B", "C"))

# With actor grouping
df$actor <- c(1, 1, 1, 2, 2)
seq_data <- prepare_onehot(df, cols = c("A", "B", "C"), actor = "actor")

# With windowing
seq_data <- prepare_onehot(df, cols = c("A", "B", "C"),
                          window_size = 2, window_type = "non-overlapping")

}
\seealso{
\code{\link{action_to_onehot}} for the reverse conversion.
}
