Drops the original column from the dataframe once bins are made. Throws an error if the same column has multiple bin cols.

drop_original_cols(.data, ..., restore_names = FALSE)

Arguments

.data

dataframe output from bin_cols

...

tidyselect. default chooses all cols created from binning

restore_names

Logical, default FALSE. rename the binned cols with the original column names?

Value

dataframe

Examples


iris %>%
 bin_cols(Sepal.Length) %>%
 bin_cols(Sepal.Width, pretty_labels = TRUE) -> iris1

iris1
#> # A tibble: 150 × 7
#>    Sepal.Width_fr9 Sepal.Length_fr10 Sepal.Length Sepal.Width Petal.Length
#>    <fct>                       <int>        <dbl>       <dbl>        <dbl>
#>  1 (3.4,3.61]                      3          5.1         3.5          1.4
#>  2 (2.8,3]                         2          4.9         3            1.4
#>  3 (3.1,3.2]                       1          4.7         3.2          1.3
#>  4 (3,3.1]                         1          4.6         3.1          1.5
#>  5 (3.4,3.61]                      2          5           3.6          1.4
#>  6 (3.61,4.4]                      4          5.4         3.9          1.7
#>  7 (3.2,3.4]                       1          4.6         3.4          1.4
#>  8 (3.2,3.4]                       2          5           3.4          1.5
#>  9 (2.8,3]                         1          4.4         2.9          1.4
#> 10 (3,3.1]                         2          4.9         3.1          1.5
#> # … with 140 more rows, and 2 more variables: Petal.Width <dbl>, Species <fct>

iris1 %>%
 drop_original_cols(restore_names = TRUE)
#> # A tibble: 150 × 5
#>    Sepal.Width Sepal.Length Petal.Length Petal.Width Species
#>    <fct>              <int>        <dbl>       <dbl> <fct>  
#>  1 (3.4,3.61]             3          1.4         0.2 setosa 
#>  2 (2.8,3]                2          1.4         0.2 setosa 
#>  3 (3.1,3.2]              1          1.3         0.2 setosa 
#>  4 (3,3.1]                1          1.5         0.2 setosa 
#>  5 (3.4,3.61]             2          1.4         0.2 setosa 
#>  6 (3.61,4.4]             4          1.7         0.4 setosa 
#>  7 (3.2,3.4]              1          1.4         0.3 setosa 
#>  8 (3.2,3.4]              2          1.5         0.2 setosa 
#>  9 (2.8,3]                1          1.4         0.2 setosa 
#> 10 (3,3.1]                2          1.5         0.1 setosa 
#> # … with 140 more rows

iris1 %>%
 drop_original_cols(restore_names = FALSE)
#> # A tibble: 150 × 5
#>    Sepal.Width_fr9 Sepal.Length_fr10 Petal.Length Petal.Width Species
#>    <fct>                       <int>        <dbl>       <dbl> <fct>  
#>  1 (3.4,3.61]                      3          1.4         0.2 setosa 
#>  2 (2.8,3]                         2          1.4         0.2 setosa 
#>  3 (3.1,3.2]                       1          1.3         0.2 setosa 
#>  4 (3,3.1]                         1          1.5         0.2 setosa 
#>  5 (3.4,3.61]                      2          1.4         0.2 setosa 
#>  6 (3.61,4.4]                      4          1.7         0.4 setosa 
#>  7 (3.2,3.4]                       1          1.4         0.3 setosa 
#>  8 (3.2,3.4]                       2          1.5         0.2 setosa 
#>  9 (2.8,3]                         1          1.4         0.2 setosa 
#> 10 (3,3.1]                         2          1.5         0.1 setosa 
#> # … with 140 more rows