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")
Run the code above in your browser using DataLab