dot-drop_levels_keep_label: Drop unused factor levels while preserving label attribute

.drop_levels_keep_labelR Documentation

Drop unused factor levels while preserving label attribute

Description

Helper function to drop unused levels from a factor variable while preserving the label attribute. The base R droplevels() function strips all attributes except levels and class, which causes the loss of variable labels that are commonly used in clinical trial datasets.

Usage

.drop_levels_keep_label(x)

Arguments

x

(factor) A factor variable, potentially with a label attribute.

Value

The input factor with unused levels dropped and the label attribute preserved.


teal.slice documentation built on June 4, 2026, 5:07 p.m.