View source: R/design_structure.R
| expand_periods | R Documentation |
Repeats every unit's row once per period, numbering the periods and adding the elapsed time each period falls at. Units may be followed for different numbers of periods, and the spacing may be regular or irregular. A set of wide columns, one per period, can be gathered into a single long value column at the same time.
expand_periods(
data,
periods = NULL,
id = "id",
period = "period",
period_values = NULL,
interval_mean = NULL,
interval_dispersion = 0,
time = "time",
time_variables = NULL,
value = "value",
seed = NULL
)
data |
Base |
periods |
Number of periods: a single whole number applied to every
unit, the name of a column of |
id |
Identifier variable. A single string naming a column of |
period |
Name of the period column. A single non-empty string,
defaulting to |
period_values |
Optional atomic vector of period values shared by every
unit, used in place of the numbering above. Defaults to |
interval_mean |
Mean interval between consecutive periods: a single
number, the name of a column of |
interval_dispersion |
Dispersion of the gamma-distributed intervals: a
single non-negative number, or the name of a column of |
time |
Name of the generated elapsed-time column, which starts at |
time_variables |
Optional character vector of wide columns of |
value |
Name of the gathered time-varying value. A single non-empty
string, defaulting to |
seed |
Optional random seed for irregular intervals. A single number, or
|
A simulab_sim base data.frame with one row per unit-period,
holding the columns of data plus the period and elapsed-time columns, and
the gathered value column in place of time_variables when those are
given. The component schedule, reached with
as.data.frame(x, what = "schedule"), holds one row per input unit with
columns input_row, id, periods, interval_mean and
interval_dispersion.
data <- data.frame(id = 1:10)
result <- expand_periods(data, periods = 4, id = "id", period = "period")
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.