defined()
constructs a vector enriched with semantic metadata such as a
label, unit of measurement, concept URI, and optional namespace.
These vectors behave like base R vectors but retain metadata during
subsetting, comparison, and printing.
Usage
defined(
x,
labels = NULL,
label = NULL,
unit = NULL,
concept = NULL,
namespace = NULL,
...
)
is.defined(x)
# S3 method for class 'haven_labelled_defined'
summary(object, ...)
Arguments
- x
A vector of type character, numeric, Date, factor, or a
labelled
object.- labels
An optional named vector of value labels. Only a subset of values may be labelled.
- label
A short human-readable label (string of length 1).
- unit
Unit of measurement (e.g., "kg", "hours"). Must be a string of length 1 or
NULL
.- concept
A URI or concept name representing the meaning of the variable.
- namespace
Optional string or named character vector, used for value-level URI expansion.
- ...
Reserved for future use.
- object
An R object to be summarised.
Value
A vector of class "defined"
(technically
haven_labelled_defined
), which behaves like a standard vector with
additional semantic metadata and is inherited from haven::labelled()
.
Details
The resulting object inherits from haven::labelled()
and integrates with
tidyverse workflows, enabling downstream conversion to RDF and other
standards.
See also
browseVignettes("dataset")
is.defined()
, as_numeric()
, as_character()
, as_factor()
,
strip_defined()
Examples
gdp_vector <- defined(
c(3897, 7365, 6753),
label = "Gross Domestic Product",
unit = "million dollars",
concept = "http://data.europa.eu/83i/aa/GDP"
)
# To check the s3 class of the vector:
is.defined(gdp_vector)
#> [1] TRUE
# To print the defined vector:
print(gdp_vector)
#> gdp_vector: Gross Domestic Product
#> Defined as http://data.europa.eu/83i/aa/GDP, measured in million dollars
#> [1] 3897 7365 6753
# To summarise the defined vector:
summary(gdp_vector)
#> Gross Domestic Product (million dollars)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 3897 5325 6753 6005 7059 7365
# Subsetting work as expected:
gdp_vector[1:2]
#> x: Gross Domestic Product
#> Defined as http://data.europa.eu/83i/aa/GDP, measured in million dollars
#> [1] 3897 7365