Learn R Programming

AnimalSequences (version 0.2.0)

sequences_to_long: Convert Sequences to Long Format

Description

This function converts a data frame with sequences into long format. It expands each sequence into individual rows, optionally including start and end times and covariates.

Usage

sequences_to_long(
  sequences,
  sequence = "sequence",
  start_time = NULL,
  end_time = NULL,
  covariates = NULL
)

Value

A data frame in long format with sequences, start time, end time, duration, and covariates.

Arguments

sequences

A data frame containing sequences.

sequence

Column name with the sequences.

start_time

Column name with the start time. Defaults to NULL.

end_time

Column name with the end time. Defaults to NULL.

covariates

A vector with column names of the covariates. Defaults to NULL.

Examples

Run this code
sequences <- data.frame(sequence = c('A B C', 'A B', 'A C', 'B C'),
                        covariate1 = c('X', 'Y', 'X', 'Y'),
                        covariate2 = c('M', 'N', 'M', 'N'))
sequences_to_long(sequences,
                  sequence = 'sequence',
                  covariates = c('covariate1', 'covariate2'))

Run the code above in your browser using DataLab