defined | R Documentation |
Creates a semantically well-defined vector enriched with metadata.
defined()
is an S3 constructor that extends numeric or character vectors
with a human-readable label, unit of measurement, linked concept,
and optional namespace. These objects preserve semantics while behaving
like standard vectors in comparisons, printing, and subsetting.
The defined
constructor creates the objects of this
class, which are semantically extended vectors inherited from
haven::labelled
.
defined(
x,
labels = NULL,
label = NULL,
unit = NULL,
concept = NULL,
namespace = NULL,
...
)
is.defined(x)
## S3 method for class 'haven_labelled_defined'
summary(object, ...)
x |
A vector to label. Must be either numeric (integer or double) or character. |
labels |
A named vector or |
label |
A short, human-readable description of the vector or |
unit |
A character string of length one containing the unit of measure
or |
concept |
A character string of length one containing a linked
concept or |
namespace |
A namespace for individual observations or categories or
|
... |
Further parameters for inheritance, not in use. |
object |
An R object to be summarised. |
A defined
vector is an extension of a base vector with additional
semantic metadata:
A label (label
): a short human-readable description
A unit (unit
): e.g., "kg", "hours", "USD"
A concept (concept
): a URI or textual reference
A namespace (namespace
): for URI-based observation or value identifiers
The class inherits from haven::labelled
, supports typical vector
operations (subsetting, comparisons, printing), and integrates with
tibbles and tidy workflows via custom format()
, print()
, and
as.vector()
methods.
Use is.defined()
to test if an object is of class defined
.
Use as_numeric()
and as_character()
to coerce to base types.
The constructor defined
returns a vector with defined value
labels, a variable label, an optional unit of measurement and linked
concept.
is.defined
returns a logical value, stating if the
object is of class defined
.
Other defined metadata methods and functions:
var_label()
,
var_namespace()
,
var_unit()
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)
# To print the defined vector:
print(gdp_vector)
# To summarise the defined vector:
summary(gdp_vector)
# Subsetting work as expected:
gdp_vector[1:2]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.