as_numeric() converts a defined() vector to a numeric vector.
It validates that the underlying data are numeric, and optionally preserves
or strips semantic metadata.
Usage
as_numeric(x, ...)
# S3 method for class 'haven_labelled_defined'
as_numeric(x, strip_attributes = TRUE, ...)Arguments
- x
A vector created with
defined().- ...
Reserved for future use.
- strip_attributes
Logical; whether to remove semantic metadata (
label,unit,concept,namespace). Defaults toTRUE.
Details
Use strip_attributes = TRUE when flattening or preparing data for
external pipelines, but keep the default when working with defined
vectors directly.
as.numeric() drops all metadata and returns only the numeric values in
a vector.
Examples
x <- defined(
1:3,
label = "Count",
unit = "n",
concept = "http://example.org/count",
namespace = "http://example.org/ns"
)
as_numeric(x)
#> [1] 1 2 3
