to_factor: Convert vector to factor/character with corresponding...

Description Usage Arguments Value Functions See Also Examples

View source: R/to_factor.R

Description

to_factor Convert vector to factor with corresponding value labels or unique values in the vector. Note that the 'NA' or blank values will be excluded. It will return a factor with original values if there's no value label.

Usage

1
2
3
4
5

Arguments

x

vector

ordered

logical flag to determine if the levels should be regarded as ordered.

Value

Factor of the same form as x but with value labels instead of values.

Functions

See Also

val_lab, var_lab

Examples

1
2
3
4
5
6
7
8
data(mtcars)
mtcars = within(mtcars,{
                var_lab(am) = "Transmission"
                val_lab(am) = c(" automatic" = 0, " manual" =  1)
})

mtcars$am <- to_factor(mtcars$am)
mtcars$gear <- to_character(mtcars$gear)

adayim/cttab documentation built on Dec. 18, 2021, 10:27 p.m.