Learn R Programming

dataset (version 0.4.1)

as_numeric: 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 haven_labelled_defined as_numeric(x, strip_attributes = TRUE, ...)

Value

A numeric vector with or without preserved attributes.

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.

Examples

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

as_numeric(x)

Run the code above in your browser using DataLab