Learn R Programming

expss (version 0.5.5)

f: Convert labelled variable to factor

Description

f converts labelled variable to factor. 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 variable doesn't have labels then usual factor will be applied.

Usage

f(x, ...)

Arguments

x
a vector of data with labels.
...
optional arguments for factor

Value

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

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)

## Not run: 
# plot(f(mtcars$am))
# ## End(Not run)

table(f(mtcars$am))

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

Run the code above in your browser using DataLab