| prepare_data | R Documentation |
Processes a dataset to create user sessions based on time gaps, ordering columns, or actor groupings. It supports different ways to understand order in user behavior and provides flexibility when widening the data.
prepare_data(
data,
actor,
time,
action,
order,
time_threshold = 900,
custom_format = NULL,
is_unix_time = FALSE,
unix_time_unit = "seconds",
unused_fn = dplyr::first,
timezone = "UTC",
session = NULL
)
data |
A |
actor |
A |
time |
A |
action |
A |
order |
A |
time_threshold |
A positive |
custom_format |
A |
is_unix_time |
A |
unix_time_unit |
A |
unused_fn |
How to handle extra columns when pivoting to wide format.
See |
timezone |
An Olson time zone used to interpret timestamps that do not
contain an explicit UTC offset. Explicit offsets such as |
session |
An optional tidy selection of one or more columns identifying
explicit sessions within actors, such as a course or semester. When |
Session identity is based on observed combinations of the original
actor and session columns. Separator characters and high-cardinality
marginal levels therefore cannot merge distinct sessions. .session_id is
the collision-safe key and .session_label is its readable display label.
A tna_data object, which is a list with the following elements:
long_data: The processed data in long format.
sequence_data: The processed data on the sequences in wide format,
with actions/events as different variables structured with sequences.
meta_data: Other variables from the original data in wide format.
time_data: Parsed timestamps in wide format when time is supplied,
or NULL otherwise.
statistics: A list containing summary statistics:
total_sessions, total_actions, max_sequence_length,
unique_users, sessions_per_user and actions_per_session (tibbles
with one row per user and per session), and time_range (when time
is supplied).
The statistics are also reported as messages while the data is
prepared. print.tna_data() prints the sequence data, the metadata, or
the long data.
Other data:
import_data(),
import_onehot(),
list_random_state_pools(),
print.tna_data(),
random_group_tna(),
random_tna(),
random_tna_mmm(),
simulate.group_tna(),
simulate.tna()
results <- prepare_data(
group_regulation_long, actor = "Actor", time = "Time", action = "Action"
)
print(results)
print(results, data = "meta")
# Custom order column
data_ordered <- tibble::tibble(
user = c("A", "A", "A", "B", "B", "C", "C", "C"),
order = c(1, 2, 3, 1, 2, 1, 2, 3),
action = c(
"view", "click", "add_cart", "view",
"checkout", "view", "click", "share"
)
)
results_ordered <- prepare_data(
data_ordered, actor = "user", order = "order", action = "action"
)
print(results_ordered)
# No actor scenario leading to a single session
data_single_session <- tibble::tibble(
action = c(
"view", "click", "add_cart", "view",
"checkout", "view", "click", "share"
)
)
results_single <- prepare_data(data_single_session, action = "action")
print(results_single)
# Multiple actors
data_multi_actor <- tibble::tibble(
user = c("A", "A", "A", "A", "B", "B", "B", "B"),
session = c(1, 1, 2, 2, 1, 1, 2, 2),
action = c(
"view", "click", "add_cart", "view",
"checkout", "view", "click", "share"
)
)
results_multi_actor <- prepare_data(
data_multi_actor, actor = c("user", "session"), action = "action"
)
print(results_multi_actor)
print(results_multi_actor, data = "meta")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.