Discretization
Usage
discretize(
x,
n = 5,
method = "natural",
large = 3000,
prop = 0.15,
seed = 42,
thr = 0.4,
iter = 100,
bps = NULL,
right_closed = TRUE
)Arguments
- x
A vector.
- n
(optional) Number of classes.
- method
(optional) Discretization method. One of
"sd","equal","geometric","quantile","manual","natural("jenks")", or"headtail"("headtails").- large
(optional) Threshold sample size for natural breaks sampling.
- prop
(optional) Sampling proportion used when
method = "natural"and the input size exceedslarge.- seed
(optional) Random seed used for sampling in natural breaks.
- thr
(optional) Threshold used in the head/tail breaks algorithm.
- iter
(optional) Maximum number of iterations for head/tail breaks.
- bps
(optional) Numeric vector of manual breakpoints used when
method = "manual".- right_closed
(optional) Logical. If
TRUE, intervals are right-closed (e.g.,(a, b]). IfFALSE, intervals are left-closed[a, b).
Note
If x is not numeric, or if the number of unique non-NA values
is less than or equal to n (except for the "headtail"("headtails") method),
the function falls back to integer encoding via as.factor().
In all cases, missing values (NA/NaN) are ignored and returned as class 0.