Skip to content

Instantly share code, notes, and snippets.

@ATpoint
Last active May 5, 2025 08:51
Show Gist options
  • Save ATpoint/7245d64a0a5438d3bd6d630b189416df to your computer and use it in GitHub Desktop.
Save ATpoint/7245d64a0a5438d3bd6d630b189416df to your computer and use it in GitHub Desktop.
Functio
get_rle_ranges <- function(x) {
rle_out <- rle(x)
rle_lengths <- rle_out$lengths
ends <- cumsum(rle_lengths)
starts <- c(1, head(ends, -1) + 1)
lens <- (ends - starts) + 1
data.frame(run = seq_along(rle_lengths), start = starts, end = ends, length = lens)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment