dropUnusedFactorLevels | R Documentation |
Drop Unused Factor Levels in all Factor Columns
dropUnusedFactorLevels(data, dbg = TRUE)
data |
data frame in which to remove unused levels in all columns that are factors |
dbg |
if |
data
with unused factors removed in all columns being factors
# Create an example data frame with two factor columns
data <- data.frame(
id = 1:3,
factor_1 = factor(c("a", "b", "a"), levels = c("a", "b", "c")),
factor_2 = factor(c("x", "x", "y"), levels = c("x", "y", "z")),
no_factor = c("A", "B", "C"),
stringsAsFactors = FALSE
)
# Review the structure of the data frame
str(data)
# Review the structure of the data frame with unused factors removed
str(dropUnusedFactorLevels(data))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.