cutter: Discretise numeric x values into categorical

cutterR Documentation

Discretise numeric x values into categorical

Description

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

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.

Value

factor with appropriate levels

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()
cutter_number(animals, 10, tpq, taq,) %>% table()
cutter_width(animals, 30, tpq, taq) %>% table()

# # 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()


vbonhomme/pataqu documentation built on April 24, 2022, 10:03 p.m.