as_numeric: Coerce a defined vector to numeric

View source: R/as_numeric.R

as_numericR Documentation

Coerce a defined vector to numeric

Description

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 to TRUE.

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.

Value

A numeric vector with or without preserved attributes.

Examples

x <- defined(
     1:3,
     label = "Count",
     unit = "n",
     concept = "http://example.org/count",
     namespace = "http://example.org/ns"
)

as_numeric(x)


dataset documentation built on Nov. 16, 2025, 5:06 p.m.