longitudinal_array {long2lstmarray} | R Documentation |
Generate a matrix with various lags from a dataframe
Description
Generate a matrix with various lags from a dataframe
Usage
longitudinal_array(
data,
subj_var,
vars,
time_var,
lags,
label_length = 1,
label_var = NULL,
label_output = FALSE,
time_var_output = FALSE
)
Arguments
data |
A data frame, data frame extension (e.g. a |
subj_var |
A character string referring to the variable that specifies the "subject" variable. |
vars |
A character string referring to the variables that contain the variable values. |
time_var |
A character string referring to the variable that contains the time variable values (e.g. visit day, minutes, years). Important to get the sequences in the right order. |
lags |
The length of each sliced sequence. |
label_length |
How many values after are considered to be
the label? Default to 1. If |
label_var |
A character string referring to the variables that contain the label variable values. |
label_output |
logical. if |
time_var_output |
logical. Is |
Value
If label_output
is FALSE
, a 3D array with the
sliced sequences is returned. The array dimensions are
subject, time and variable.
If label_output
is TRUE
, a list with the array
and vector with the labels is returned.
Examples
longitudinal_array(alsfrs_data, "subjid", c("p1", "p2", "p3"),
"visdy", lags = 3, label_output = FALSE)
longitudinal_array(alsfrs_data, "subjid", c("p1", "p2", "p3"),
"visdy", lags = 3, label_output = FALSE)[1,,]
longitudinal_array(alsfrs_data, "subjid", c("p1", "p2", "p3"),
"visdy", lags = 3, label_output = FALSE)[,1,]
longitudinal_array(alsfrs_data, "subjid", c("p1", "p2", "p3"),
"visdy", lags = 3, label_output = FALSE)[,,1]