long_to_sequences {AnimalSequences} | R Documentation |
Convert Long Format to Sequences
Description
This function converts a data frame in long format into sequences by combining all rows with the same sequence identifier. It also aggregates covariates if provided.
Usage
long_to_sequences(
sequences_long,
elements = "element",
sequence_identifier = "sequence_identifier",
start_time = "start_time",
end_time = "end_time",
covariates = NULL
)
Arguments
sequences_long |
A data frame in long format containing the sequences. |
elements |
Column name for elements that should be combined into sequences. |
sequence_identifier |
Column name with the sequence identifier. |
start_time |
Column name with the start time. |
end_time |
Column name with the end time. |
covariates |
A vector with column names of the covariates. Defaults to NULL. |
Value
A data frame with sequences, start time, end time, and aggregated covariates.
Examples
sequences_long <- data.frame(sequence_identifier = c(1, 1, 2, 2, 2),
element = c('A', 'B', 'A', 'B', 'C'),
start_time = c(1, 2, 1, 2, 3),
end_time = c(2, 3, 2, 3, 4),
covariate1 = c('X', 'Y', 'X', 'Y', 'Z'),
covariate2 = c('M', 'N', 'M', 'N', 'O'))
long_to_sequences(sequences_long,
elements = 'element',
sequence_identifier = 'sequence_identifier',
start_time = 'start_time',
covariates = c('covariate1', 'covariate2'))
[Package AnimalSequences version 0.2.0 Index]