OrderedToNumeric: Convert an ordered factor to a numeric vector.

View source: R/variable.R

OrderedToNumericR Documentation

Convert an ordered factor to a numeric vector.

Description

Convert an ordered factor to a numeric vector.

Usage

OrderedToNumeric(x)

Arguments

x

An ordered factor.

Details

It is first checked if x is a categorical variable set (question) from Displayr (Q), in which case their value attributes are used. To check this, (x is searched for attributes "questiontype", and "sourcevalues", "values", "codeframe" (for "PickOne" questiontype/vector x) and "sourcevariablevalues", "variablevalues", and "codeframe" attributes, in the case of "PickOneMulti" questiontype/data.frame x). See the Examples.

If x is missing these attributes, Unclass is used. If all labels of x (or columns of x) can be coerced to numeric, these values will be used to create the numeric variable; otherwise, the integers 1, 2, ... as per the ordering of the factors.

See Also

numbersFromCategoricalVariableSets, Unclass

Examples

file <- system.file("extdata", "variable.sets.rda", package = "flipTransformations")
vs.env <- new.env()
load(file, vs.env)
ord.num <- AsNumeric(vs.env$ordinal, TRUE)
## Compare
table(ord.num)
levels(vs.env$ordinal)

NumbersInternational/flipTransformations documentation built on Feb. 26, 2024, 6:43 a.m.