Skip to contents

Thin wrappers around ggplot2::cut_interval() and friends. Useful for defining fixed x values for fitting functions.

Usage

cutter_interval(df, n, ...)

cutter_number(df, n, ...)

cutter_width(df, width, ...)

cutter_to_seq(x)

Arguments

df

a tibble()

n

number of intervals to create or the approximate number of observations

...

colnames

width

width of intervals to create

x

a cutter on which to extract breaks

Value

factor with appropriate levels

Details

Here, columns of interest may be passed directly. If you want to cut directly on numeric vectors, use base::cut() or ggplot2::cut_interval() and friends.

Functions

  • cutter_interval: makes groups with equal range

  • cutter_number: makes n groups with approximately equal numbers of observations

  • cutter_width: makes groups of a certain width

  • cutter_to_seq: extract breaks from a cutter factor

Examples


cutter_interval(animals, 30, tpq, taq) %>% table()
#> .
#>   [-175,-146]   (-146,-117]  (-117,-87.5] (-87.5,-58.3] (-58.3,-29.2] 
#>             4             0           125            25           571 
#>     (-29.2,0]      (0,29.2]   (29.2,58.3]   (58.3,87.5]    (87.5,117] 
#>           544           389           131           536           364 
#>     (117,146]     (146,175]     (175,204]     (204,233]     (233,262] 
#>            79           460           383           482           215 
#>     (262,292]     (292,321]     (321,350]     (350,379]     (379,408] 
#>           357           544            67            18           164 
#>     (408,438]     (438,467]     (467,496]     (496,525]     (525,554] 
#>            36             0             0            30             0 
#>     (554,583]     (583,612]     (612,642]     (642,671]     (671,700] 
#>             0             6             0             0             3 
cutter_number(animals, 10, tpq, taq,) %>% table()
#> .
#> [-175,-50]    (-50,0]     (0,30]    (30,70]   (70,125]  (125,200]  (200,220] 
#>        633        636        412        572        515        843        436 
#>  (220,265]  (265,300]  (300,700] 
#>        491        671        324 
cutter_width(animals, 30, tpq, taq) %>% table()
#> .
#> [-195,-165] (-165,-135] (-135,-105]  (-105,-75]   (-75,-45]   (-45,-15] 
#>           4           0           0         150         479         162 
#>    (-15,15]     (15,45]     (45,75]    (75,105]   (105,135]   (135,165] 
#>         759         136         632         365          81         411 
#>   (165,195]   (195,225]   (225,255]   (255,285]   (285,315]   (315,345] 
#>          51         859         179         397         544           0 
#>   (345,375]   (375,405]   (405,435]   (435,465]   (465,495]   (495,525] 
#>          85         164          36           0           0          30 
#>   (525,555]   (555,585]   (585,615]   (615,645]   (645,675]   (675,705] 
#>           0           0           6           0           0           3 

# # note that in x_cut_number above, we have many observations yet
# the number of _different_ levels is not so diverse,
# so that n=30 would fail with "Insufficient data values"
# unlist(animals[, c("tpq", "taq")]) %>% table()

# cutter_to_seq is helpful to pass x_bin/x_pred to bin/fit_* respectively
# there is an example in ?bin that can be used to fit_* too
# cutter_to_seq go back to numeric from factor levels:
cutter_width(animals, 30, tpq, taq) %>% cutter_to_seq()
#>  [1] -195 -165 -135 -105  -75  -45  -15   15   45   75  105  135  165  195  225
#> [16]  255  285  315  345  375  405  435  465  495  525  555  585  615  645  675
#> [31]  705