Import One-Hot Data
Usage
import_onehot(
data,
cols,
actor,
session,
interval,
window_size = 1L,
window_type = "tumbling",
aggregate = FALSE
)Arguments
- data
A
data.framein wide format.- cols
An
expressiongiving a tidy selection of columns to be considered as one-hot data.- actor
An optional
characterstring giving the column name ofdatacontaining the actor identifiers.- session
An optional
characterstring giving the column name ofdatacontaining the session identifiers.- interval
An
integerthat defines how many windows can appear at most per one row of the output data. If not provided (the default), all windows are concatenated per actor/session combination.- window_size
An
integerspecifying the window size for grouping.- window_type
A
characterstring. Either"tumbling"(the default) for non-overlapping windows or"sliding"for one-step sliding window.- aggregate
A
logicalvalue that determines how multiple occurrences of the same event within a window are processed. OptionTRUEaggregates multiple occurrences into a single occurrence. OptionFALSEkeeps all occurrences (the default).
Value
A tibble in wide format with one row per actor/session
combination (or per interval windows) and one column per time point,
named W<window>_T<position>. Each cell holds the name of the column of
cols that was active, or NA. The result can be passed to
build_model(), for example with type = "co-occurrence".
Examples
set.seed(1)
d <- data.frame(
actor = gl(100, 5),
session = gl(10, 50),
feature1 = rbinom(500, 1, prob = 0.33),
feature2 = rbinom(500, 1, prob = 0.25),
feature3 = rbinom(500, 1, prob = 0.50)
)
onehot1 <- import_onehot(d, feature1:feature3)
onehot2 <- import_onehot(d, feature1:feature3, "actor", "session")
