Run-length encoding captures the lengths of runs of consecutive elements in a vector. Consider an example vector:
dat <- c(1, 2, 2, 2, 3, 1, 4, 4, 1, 1)
The rle function extracts each run and its length:
r <- rle(dat)
r
# Run Length Encoding
# lengths: int [1:6] 1 3 1 1 2 2
# valu...