OrderedToNumeric | R Documentation |
Convert an ordered factor to a numeric vector.
OrderedToNumeric(x)
x |
An ordered factor. |
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.
numbersFromCategoricalVariableSets
, Unclass
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.