| AsNumeric | R Documentation |
Coerces a data.frame or vector that may
contain factors into a vector or
data.frame that does not contain factors.
AsNumeric(x, binary = TRUE, name = NULL, remove.first = FALSE)
x |
The |
binary |
If |
name |
Used if |
remove.first |
Remove the first binary variable. |
Characters are treated as factors.
When binary is FALSE, it is first checked if x
is a 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, ... are used for the values.
numbersFromCategoricalVariableSets, Unclass, FactorToNumeric
file <- system.file("extdata", "variable.sets.rda", package = "flipTransformations")
vs.env <- new.env()
load(file, vs.env)
dummy.nm <- AsNumeric(vs.env$nominal.multi, TRUE)
num.nm <- AsNumeric(vs.env$nominal.merge.hide, FALSE)
## Compare
table(num.nm)
levels(vs.env$nominal.merge.hide)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.