Learn R Programming

tna (version 1.5.8)

import_onehot: Import One-Hot Data

Description

Import One-Hot Data

Usage

import_onehot(
  data,
  cols,
  actor,
  session,
  interval,
  window_size = 1L,
  window_type = "tumbling",
  aggregate = FALSE
)

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".

Arguments

data

A data.frame in wide format.

cols

An expression giving a tidy selection of columns to be considered as one-hot data.

actor

An optional character string giving the column name of data containing the actor identifiers.

session

An optional character string giving the column name of data containing the session identifiers.

interval

An integer that 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 integer specifying the window size for grouping.

window_type

A character string. Either "tumbling" (the default) for non-overlapping windows or "sliding" for one-step sliding window.

aggregate

A logical value that determines how multiple occurrences of the same event within a window are processed. Option TRUE aggregates multiple occurrences into a single occurrence. Option FALSE keeps all occurrences (the default).

See Also

Other data: import_data(), list_random_state_pools(), prepare_data(), print.tna_data(), random_group_tna(), random_tna(), random_tna_mmm(), simulate.group_tna(), simulate.tna()

Examples

Run this code
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")

Run the code above in your browser using DataLab