Learn R Programming

sjmisc (version 1.7)

drop_labels: Drop labels of zero-count values

Description

This function drops all value labels for those values that have no cases (frequencies) in a vector.

Usage

drop_labels(x)

Arguments

x
Variable (vector), data.frame or list of variables with partially added value labels (see labelled).

Value

  • x, where labels for non-labelled values are added

See Also

zap_labels and zap_unlabelled to convert (non-)labelled values into NA; fill_labels to add labels to existing, but not yet labelled values.

Examples

Run this code
rp <- rec_pattern(1, 100)
rp

# sample data
data(efc)
# recode carers age into groups of width 5
x <- rec(efc$c160age, rp$pattern)
# add value labels to new vector
set_labels(x) <- rp$labels
# watch result. due to recode-pattern, we have age groups with
# no observations (zero-counts)
frq(as_labelled(x))

# now, let's drop zero's
frq(as_labelled(drop_labels(x)))

Run the code above in your browser using DataLab