Skip to contents

breaks_to_interval() takes a specified set of breaks representing the left hand limits of a closed open interval, i.e [x, y), and returns the corresponding interval and upper bounds. The resulting intervals span from the minimum break through to a specified max_upper.

Usage

breaks_to_interval(breaks, max_upper = Inf)

Arguments

breaks

[integerish].

1 or more non-negative cut points in increasing (strictly) order.

These correspond to the left hand side of the desired intervals (e.g. the closed side of [x, y).

Double values are coerced to integer prior to categorisation.

max_upper

[numeric]

Represents the maximum upper bound splitting the data.

Defaults to Inf.

Value

A tibble with an ordered factor column (interval), as well as columns corresponding to the explicit bounds (lower_bound and upper_bound). Note that even those these bounds are whole numbers they are returned as numeric to allow the maximum upper bound to be given as Inf.

Examples


breaks_to_interval(breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L))
#> # A tibble: 7 × 3
#>   interval  lower_bound upper_bound
#>   <ord>           <dbl>       <dbl>
#> 1 [0, 1)              0           1
#> 2 [1, 5)              1           5
#> 3 [5, 15)             5          15
#> 4 [15, 25)           15          25
#> 5 [25, 45)           25          45
#> 6 [45, 65)           45          65
#> 7 [65, Inf)          65         Inf
breaks_to_interval(
    breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L),
    max_upper = 100L
)
#> # A tibble: 7 × 3
#>   interval  lower_bound upper_bound
#>   <ord>           <dbl>       <dbl>
#> 1 [0, 1)              0           1
#> 2 [1, 5)              1           5
#> 3 [5, 15)             5          15
#> 4 [15, 25)           15          25
#> 5 [25, 45)           25          45
#> 6 [45, 65)           45          65
#> 7 [65, 100)          65         100