Skip to contents

A modified as.numeric() method that retains the variable label, if it exists.

Usage

as_numeric(x)

Arguments

x

A numeric vector

Value

A declared or labelled variable as numeric.

Examples

x <- declared(
 c(1:5, -1),
 labels = c(Good = 1, Bad = 5, DK = -1),
 na_values = -1
)
attr(x, "label") <- "Example"
as_numeric(x)
#> [1]  1  2  3  4  5 NA
#> attr(,"label")
#> [1] "Example"