Description Usage Arguments Value Examples
Consolidate levels into other category
1 | leaf_other(tbl, cutoff, other = "Other", inclusive = TRUE)
|
tbl |
A data frame with three columns – |
cutoff |
The proportion below which levels will be turned to other |
other |
A string indicating the name to be used for the other category, defaults to "Other" |
inclusive |
If TRUE, when a variable's other category is still below the cutoff, the next smallest level will also be converted to other. If FALSE, the other category may remain below the cutoff |
A data frame where levels with proportions below the cutoff are consolidated into an "other" category
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Set up an example data frame with some very small levels
df <- dplyr::tibble(
variable = c(rep("letter", 4), rep("number", 4)),
level = c(letters[1:4], 1:4),
proportion = c(0.6, 0.395, 0.0045, 0.0045, 0.6, 0.395, 0.0055, 0.0035)
)
# Consolidate small categories so that all values are above the cutoff
leaf_other(df, cutoff = 0.005)
# You can give a different name to the other category
leaf_other(df, cutoff = 0.005, other = "REDACTED")
leaf_other(df, cutoff = 0.005, other = NA)
# If the other category is smaller than the cutoff, leaf_other() will convert
# the next smallest value to other, even if it is larger than the cutoff.
# Use `inclusive = FALSE` to only convert categories smaller than the cutoff.
leaf_other(df, cutoff = 0.005, inclusive = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.