Learn R Programming

teal.slice (version 0.8.2)

.drop_levels_keep_label: 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)

Value

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

Arguments

x

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