to_value | R Documentation |
This function converts (replaces) factor levels with the
related factor level index number, thus the factor is converted to
a numeric variable. to_value()
and to_numeric()
are aliases.
to_value(x, ..., start.at = NULL, keep.labels = TRUE, use.labels = FALSE)
x |
A vector or data frame. |
... |
Optional, unquoted names of variables that should be selected for
further processing. Required, if |
start.at |
Starting index, i.e. the lowest numeric value of the variable's
value range. By default, this argument is |
keep.labels |
Logical, if |
use.labels |
Logical, if |
A numeric variable with values ranging either from start.at
to
start.at
+ length of factor levels, or to the corresponding
factor levels (if these were numeric). If x
is a data frame,
the complete data frame x
will be returned, where variables
specified in ...
are coerced to numeric; if ...
is
not specified, applies to all variables in the data frame.
This function is kept for backwards-compatibility. It is preferred to
use as_numeric
.
library(sjlabelled)
data(efc)
test <- as_label(efc$e42dep)
table(test)
table(to_value(test))
# Find more examples at '?sjlabelled::as_numeric'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.