num.slice | R Documentation |
num.slice
implements manual discretization of numeric vector for a given boundaries. This procedure is one
of the helper functions which are handy for the model monitoring phase (i.e. after model implementation).
num.slice(x, mapping, sc = c(NA, NaN, Inf, -Inf), sc.r = "SC")
x |
Numeric vector to be discretized. |
mapping |
Data frame with compulsory columns: |
sc |
Numeric vector with special case elements. Default values are |
sc.r |
Character vector used for replacement of special cases. If supplied as one
element vector, it will be recycled to the length of |
The command num.slice
returns vector of discretized values and coded special cases.
suppressMessages(library(PDtoolkit))
data(gcd)
x <- gcd$maturity
#artificially add some special values
x[1:5] <- Inf
x[6:7] <- NA
#perform monotonic grouping in order to get bins' boundaries
mbin <- sts.bin(x = x, y = gcd$qual, sc.method = "separately")
mbin[[1]]
#slice numeric variable
sn <- num.slice(x = x,
mapping = data.frame(x.min = mbin[[1]]$x.min[-c(1, 2)],
x.max = mbin[[1]]$x.max[-c(1, 2)]),
sc = c(NA, NaN, Inf, -Inf),
sc.r = "SC")
#compare automatic and manual binning
table(mbin[[2]], useNA = "always")
table(sn, useNA = "always")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.