One might want to group their data by the runs of a variable and perform some sort of analysis. Consider the following simple dataset:
(dat <- data.frame(x = c(1, 1, 2, 2, 2, 1), y = 1:6))
# x y
# 1 1 1
# 2 1 2
# 3 2 3
# 4 2 4
# 5 2 5
# 6 1 6
The variable x has three runs: a run of l...