The extract() extract binned variable from "bins", "optimal_bins" class object.

extract(x)

# S3 method for bins
extract(x)

Arguments

x

a bins class or optimal_bins class.

Value

factor.

Details

The "bins" and "optimal_bins" class objects use the summary() and plot() functions to diagnose the performance of binned results. This function is used to extract the binned result if you are satisfied with the result.

See also

Examples

library(dplyr)

# Generate data for the example
heartfailure2 <- heartfailure
heartfailure2[sample(seq(NROW(heartfailure2)), 5), "creatinine"] <- NA

# optimal binning using binning_by()
bin <- binning_by(heartfailure2, "death_event", "creatinine")
#> Warning: The factor y has been changed to a numeric vector consisting of 0 and 1.
#> 'Yes' changed to 1 (positive) and 'No' changed to 0 (negative).
bin
#> binned type: optimal
#> number of bins: 3
#> x
#> [0.5,0.9] (0.9,1.8] (1.8,9.4]      <NA> 
<<<<<<< HEAD
#>        80       166        48         5 
=======
#>        78       168        48         5 
>>>>>>> 2455413f029244b566a37aeed1916eea79ac483b

if (!is.null(bin)) {
  # extract binning result
  extract(bin) %>% 
    head(20)
}
#>  [1] (1.8,9.4] (0.9,1.8] (0.9,1.8] (1.8,9.4] (1.8,9.4] (1.8,9.4] (0.9,1.8]
<<<<<<< HEAD
#>  [8] (0.9,1.8] (0.9,1.8] (1.8,9.4] (1.8,9.4] [0.5,0.9] (0.9,1.8] (0.9,1.8]
=======
#>  [8] (0.9,1.8] (0.9,1.8] (1.8,9.4] (1.8,9.4] [0.5,0.9] <NA>      (0.9,1.8]
>>>>>>> 2455413f029244b566a37aeed1916eea79ac483b
#> [15] (0.9,1.8] (0.9,1.8] [0.5,0.9] [0.5,0.9] (0.9,1.8] (1.8,9.4]
#> Levels: [0.5,0.9] < (0.9,1.8] < (1.8,9.4]