Learn R Programming

AnimalSequences (version 0.2.0)

calculate_transition_counts: Calculate Transition Counts from Sequences

Description

This function calculates the transition counts between elements in a set of sequences. It creates a matrix where each element represents the number of times a transition occurs from one element to another.

Usage

calculate_transition_counts(sequences)

Value

A matrix where the entry at [i, j] represents the number of times an element labeled i is followed by an element labeled j across all sequences.

Arguments

sequences

A vector of character strings, where each string represents a sequence of elements separated by spaces. Elements should be labeled with prefixes (e.g., "e1", "e2").

Details

The function assumes that elements in the sequences are labeled with prefixes (e.g., "e1", "e2"), which are stripped to extract the integer labels for counting. The matrix is initialized to be of size num_elements x num_elements, where num_elements should be defined in your script or session. Ensure that num_elements is set to the correct number of unique elements before running this function.

Examples

Run this code
sequences <- c("e1 e2 e3", "e2 e3 e1", "e1 e3")
num_elements <- 3
calculate_transition_counts(sequences)

Run the code above in your browser using DataLab