prepare_data {tna} | R Documentation |
Compute User Sessions from Event Data
Description
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.
Usage
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
)
Arguments
data |
A |
actor |
A |
time |
A |
action |
A |
order |
A |
time_threshold |
An |
custom_format |
A |
is_unix_time |
A |
unix_time_unit |
A |
unused_fn |
How to handle extra columns when pivoting to wide format.
See |
Value
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. -
statistics
: Alist
containing summary statistics: total sessions, total actions, unique users, time range (if applicable), and top sessions and user by activities.
See Also
Other data:
import_data()
,
print.tna_data()
,
simulate.tna()
Examples
results <- prepare_data(
group_regulation_long, actor = "Actor", time = "Time", action = "Action"
)
print(results$sequence_data)
print(results$meta_data)
print(results$statistics)
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$sequence_data)
print(results_ordered$meta_data)
print(results_ordered$statistics)
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$sequence_data)
print(results_single$meta_data)
print(results_single$statistics)