Skip to contents

Given an rle this function will return a data.frame of starts, ends, and indexes thereof of the run lengths. Credit: https://stackoverflow.com/questions/43875716/find-start-and-end-positions-indices-of-runs-consecutive-values

Usage

rle_df(x)

Arguments

x

(vector) An object for which to run an rle

Value

(data.frame)

with length, values, start and end indices.

Examples

rle_df(sample(c(TRUE,FALSE), replace = TRUE, 100))
#> # A tibble: 60 × 4
#>    lengths values start   end
#>      <int> <lgl>  <dbl> <int>
#>  1       1 TRUE       1     1
#>  2       1 FALSE      2     2
#>  3       3 TRUE       3     5
#>  4       1 FALSE      6     6
#>  5       1 TRUE       7     7
#>  6       2 FALSE      8     9
#>  7       2 TRUE      10    11
#>  8       3 FALSE     12    14
#>  9       2 TRUE      15    16
#> 10       1 FALSE     17    17
#> # ℹ 50 more rows