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, ..., = NULL, keep.labels = TRUE, use.labels = FALSE)



A vector or data frame.


Optional, unquoted names of variables that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or tidyselect's select-helpers. See 'Examples' or package-vignette.

Starting index, i.e. the lowest numeric value of the variable's value range. By default, this argument is NULL, hence the lowest value of the returned numeric variable corresponds to the lowest factor level (if factor levels are numeric) or to 1 (if factor levels are not numeric).


Logical, if TRUE, former factor levels will be added as value labels. For numeric factor levels, values labels will be used, if present. See 'Examples' and set_labels for more details.


Logical, if TRUE and x has numeric value labels, these value labels will be set as numeric values.


A numeric variable with values ranging either from to + 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.


test <- as_label(efc$e42dep)
#> test
#>          independent   slightly dependent moderately dependent 
#>                   66                  225                  306 
#>   severely dependent 
#>                  304 
#>   1   2   3   4 
#>  66 225 306 304 

# Find more examples at '?sjlabelled::as_numeric'