num.slice: Slice numeric variable

View source: R/55_HELPERS_.R

num.sliceR Documentation

Slice numeric variable

Description

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).

Usage

num.slice(x, mapping, sc = c(NA, NaN, Inf, -Inf), sc.r = "SC")

Arguments

x

Numeric vector to be discretized.

mapping

Data frame with compulsory columns: x.min and x.max which represent the discretized boundaries.

sc

Numeric vector with special case elements. Default values are c(NA, NaN, Inf, -Inf).

sc.r

Character vector used for replacement of special cases. If supplied as one element vector, it will be recycled to the length of sc. Default value is "SC".

Value

The command num.slice returns vector of discretized values and coded special cases.

Examples

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")

andrija-djurovic/PDtoolkit documentation built on Jan. 29, 2024, 9:35 a.m.