Learn R Programming

sjPlot (version 1.7)

to_value: Converts factors to numeric variables

Description

This function converts (replaces) factor values with the related factor level index number, thus the factor is converted to a numeric variable.

Usage

to_value(x, startAt = 1, keep.labels = TRUE)

Arguments

Value

A numeric variable with values ranging from startAt to startAt + length of factor levels.

See Also

Examples

Run this code
data(efc)
test <- to_label(efc$e42dep)
table(test)

table(to_value(test))
hist(to_value(test, 0))

# set lowest value of new variable
# to "5".
table(to_value(test, 5))

Run the code above in your browser using DataLab