Learn R Programming

sjPlot (version 1.7)

to_fac: Convert variable into factor and keep value labels

Description

This function converts a variable into a factor, but keeps variable and value labels, if these are attached as attributes to the variale var. See examples.

Usage

to_fac(x)

Arguments

Value

A factor variable, including variable and value labels.

See Also

Examples

Run this code
data(efc)
# normal factor conversion, loses value attributes
efc$e42dep <- as.factor(efc$e42dep)
sjt.frq(efc$e42dep)

data(efc)
# factor conversion, which keeps value attributes
efc$e42dep <- to_fac(efc$e42dep)
sjt.frq(efc$e42dep)

Run the code above in your browser using DataLab