| defined | R Documentation |
defined() constructs a vector that behaves like a base R vector but carries
semantic metadata used for documentation, validation, and interoperability.
The resulting object inherits from haven::labelled() (for numeric,
character, and factor data) or from base date/time classes, and adds:
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 annotate. |
labels |
Optional named vector of value labels. Only supported for numeric or character vectors (not for logical). |
label |
A short human-readable variable label (character of length 1). |
unit |
Unit of measurement (character length 1) or |
concept |
A URI or identifier describing the meaning or definition
of the variable. This replaces the deprecated |
namespace |
Optional string or named character vector used to generate
value-level URIs via substitution ( |
... |
For backward compatibility; the deprecated |
object |
An R object to be summarised. |
a human-readable variable label,
an optional unit of measurement,
a concept URI identifying the meaning of the variable (formerly called definition),
an optional namespace used for value-level URI expansion,
optional labelled values (where supported).
The concept attribute is a general semantic anchor and may refer to:
a measure or dimension concept (SDMX-style), a property IRI (e.g. Wikibase),
or any URI that defines or describes the variable.
defined() vectors preserve their metadata during subsetting, printing,
summarizing, comparisons, and many tidyverse operations. They integrate
smoothly with dataset_df() objects and can be safely flattened via
as.data.frame(), as_tibble(), or coercion helpers such as
as_numeric() and as_character().
A vector of class "haven_labelled_defined" or "datetime_defined",
depending on the input type.
numeric (integer or double)
character
factor (converted via labelled::to_labelled())
Date
POSIXct
haven::labelled()
logical (with restrictions: logical vectors cannot have value labels)
is.defined(),
as_numeric(),
as_character(),
as_logical(),
strip_defined(),
dataset_df()
print.haven_labelled_defined()
gdp_vector <- defined(
c(3897, 7365, 6753),
label = "Gross Domestic Product",
unit = "million dollars",
concept = "http://data.europa.eu/83i/aa/GDP"
)
is.defined(gdp_vector)
print(gdp_vector)
summary(gdp_vector)
gdp_vector[1:2]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.