dropUnusedFactorLevels: Drop Unused Factor Levels in all Factor Columns

View source: R/column.R

dropUnusedFactorLevelsR Documentation

Drop Unused Factor Levels in all Factor Columns

Description

Drop Unused Factor Levels in all Factor Columns

Usage

dropUnusedFactorLevels(data, dbg = TRUE)

Arguments

data

data frame in which to remove unused levels in all columns that are factors

dbg

if TRUE, debug messages are shown

Value

data with unused factors removed in all columns being factors

Examples

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


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.