Learn R Programming

expss (version 0.11.4)

fctr: Convert labelled variable to factor

Description

fctr converts variable to factor. It force labels usage as factor labels for labelled variables even if 'expss.enable_value_labels_support' set to 0. For other types of variables base factor is called. Factor levels are constructed as values labels. If label doesn't exist for particular value then this value remain as is - so there is no information lost. This levels look like as "Variable_label|Value label" if argument prepend set to TRUE.

Usage

fctr(x, ..., drop_unused_labels = FALSE, prepend_var_lab = TRUE)

Value

an object of class factor. For details see base factor documentation.

Arguments

x

a vector of data with labels.

...

optional arguments for factor

drop_unused_labels

logical. Should we drop unused value labels? Default is FALSE.

prepend_var_lab

logical. Should we prepend variable label before value labels? Default is TRUE.

See Also

values2labels, names2labels, val_lab, var_lab. Materials for base functions: factor, as.factor, ordered, as.ordered

Examples

Run this code
data(mtcars)

var_lab(mtcars$am) = "Transmission"
val_lab(mtcars$am) = c(automatic = 0, manual=1)

summary(lm(mpg ~ am, data = mtcars)) # no labels  
summary(lm(mpg ~ fctr(am), data = mtcars)) # with labels 
summary(lm(mpg ~ fctr(unvr(am)), data = mtcars)) # without variable label 

Run the code above in your browser using DataLab