Allows users to take a high-resolution or continuous-time longitudinal edgelist and dynamically collapse or discretize it into larger time windows. The output is a shorter, aggregated edgelist ready to be passed into [edgelist_to_adjmat] or [as_diffnet].

collapse_timeframes(
  edgelist,
  ego = "sender",
  alter = "receiver",
  timevar = "time",
  weightvar = NULL,
  window_size = 1,
  time_format = NULL,
  relative_time = TRUE,
  binarize = FALSE,
  cumulative = FALSE,
  symmetric = FALSE
)

Arguments

edgelist

A data.frame representing the longitudinal edgelist.

ego

Character scalar. Name of the column representing the ego (sender).

alter

Character scalar. Name of the column representing the alter (receiver).

timevar

Character scalar. Name of the column representing the time variable.

weightvar

Character scalar or NULL. Name of the column representing the edge weight. If NULL, the function tallies the number of interactions within the time window as the weight.

window_size

Numeric scalar. The size of the time window to collapse into.

time_format

Character scalar or NULL. If the time variable is a character or factor, the format passed to as.POSIXct. For example, "%d-%m-%Y %H:%M".

relative_time

Logical scalar. If TRUE, normalizes the binned times into a strict integer sequence starting at 1 (1, 2, 3...).

binarize

Logical scalar. If TRUE, sets all resulting edge weights to 1.

cumulative

Logical scalar. If TRUE, edges from previous time windows are carried over to subsequent windows.

symmetric

Logical scalar. If TRUE, the resulting graph will be symmetrized (i.e., if an edge A->B exists, an edge B->A is added).

Value

A data.frame with 4 columns: the ego, the alter, the new collapsed discrete time, and the aggregated weight.

Examples

if (FALSE) { # \dontrun{
# Load the package's hourly dataset
load(system.file("data/epigames_raw.rda", package = "netdiffuseR"))

# Collapse the hourly edgelist into a daily edgelist (window_size = 24)
daily_edgelist <- collapse_timeframes(
  edgelist = epigames_raw$edgelist,
  timevar = "time",
  weightvar = "weight",
  window_size = 24
)
head(daily_edgelist)
} # }