University of Fribourg, Dept. of Informatics, ASAM Group
Published
March 28, 2024
How can you easily analyse vector sequences in base R?
Run-length encoding
Flying over the GitHub repository about useful and powerful shortcuts in base R, I stumbled upon an easy way to split a vector into sequences of equal values.
The function rle() allows you to deconstruct a vector. This function shows the frequency of an instance in a certain sequence. If a value is followed by the same one, the rle() function will count the number of these successive instances.
The rle() function returns a list of the values and their respective lengths in a vector sequence. The class of this list is "rle".