Distribute events into groups defined by time or numerical intervals. Each set of linked records are assigned a unique identifier with relevant group-level data.

partitions(
  date,
  window = NULL,
  windows_total = 1,
  separate = FALSE,
  sn = NULL,
  strata = NULL,
  data_links = "ANY",
  custom_sort = NULL,
  group_stats = FALSE,
  data_source = NULL,
  by = NULL,
  length.out = NULL,
  fill = TRUE,
  display = "none",
  precision = 1
)

Arguments

date

[date|datetime|integer|number_line]. Event date or period.

window

[integer|number_line]. Numeric or time intervals.

windows_total

[integer|number_line]. Minimum number of matched windows required for a pane. See details

separate

[logical]. If TRUE, events matched to different windows are not linked.

sn

[integer]. Unique record identifier. Useful for creating familiar pane identifiers.

strata

[atomic]. Subsets of the dataset. Panes are created separately for each strata.

data_links

[list|character]. A set of data_sources required in each pane. A pane without records from these data_sources will be unlinked. See Details.

custom_sort

[atomic]. Preferred order for selecting "index" events.

group_stats

[logical]. If TRUE (default), the returned pane object will include group specific information like panes start and end dates.

data_source

[character]. Unique data source identifier. Adds the list of datasets in each pane to the pane. Useful when the data is from multiple sources.

by

[integer]. Width of splits.

length.out

[integer]. Number of splits.

fill

[logical]. Retain (TRUE) or drop (FALSE) the remainder of an uneven split.

display

[character]. Display a status update. Options are; "none" (default), "progress" or "stats".

precision

Round precision

Value

pane

Details

Each assigned group is referred to as a pane A pane consists of events within a specific time or numerical intervals (window).

Each window must cover a separate interval. Overlapping windows are merged before events are distributed into panes. Events that occur over two windows are assigned to the last one listed.

Alternatively, you can create windows by splitting a period into equal parts (length.out), or into a sequence of intervals with fixed widths (by).

By default, the earliest event is taken as the "Index" event of the pane. An alternative can be chosen with custom_sort. Note that this is simply a convenience option because it has no bearing on how groups are assigned.

partitions() will categorise records into 3 types;

  • "Index" - Index event/record of the pane.

  • "Duplicate_I" - Duplicate of the "Index" record.

  • "Skipped" - Records that are not assigned to a pane.

Every element in data_links must be named "l" (links) or "g" (groups). Unnamed elements of data_links will be assumed to be "l".

  • If named "l", only groups with records from every listed data_source will be retained.

  • If named "g", only groups with records from any listed data_source will be retained.

NA values in strata excludes records from the partitioning process.

See vignette("episodes") for more information.

Examples

events <- c(30, 2, 11, 10, 100)
windows <- number_line(c(1, 9, 25), c(3, 12, 35))

events
#> [1]  30   2  11  10 100
partitions(date = events, length.out = 3, separate = TRUE)
#> [1] "PN.6 (D)" "PN.6 (I)" "PN.6 (D)" "PN.6 (D)" "PN.7 (I)"
partitions(date = events, by = 10, separate = TRUE)
#> [1] "PN.8 (I)" "PN.6 (I)" "PN.6 (D)" "PN.6 (D)" "PN.5 (I)"
partitions(date = events, window = windows, separate = TRUE)
#> [1] "PN.8 (I)" "PN.6 (I)" "PN.7 (D)" "PN.7 (I)" "PN.5 (I)"
partitions(date = events, window = windows, separate = FALSE)
#> [1] "PN.1 (I)" "PN.2 (I)" "PN.3 (I)" "PN.4 (I)" "PN.5 (I)"
partitions(date = events, window = windows, separate = FALSE, windows_total = 4)
#> [1] "PN.1 (I)" "PN.2 (I)" "PN.3 (I)" "PN.4 (I)" "PN.5 (I)"