var_unit | R Documentation |
Get / Set a unit of measure
var_unit(x, ...)
var_unit(x) <- value
get_variable_units(x, ...)
unit_attribute(x)
get_unit_attribute(x)
set_unit_attribute(x, value)
unit_attribute(x) <- value
x |
A vector. |
... |
Further potential parameters reserved for inherited classes. |
value |
A character string or |
The aim of the unit
attribute is to add to the R vector object its
unit of measure (for example, physical units like gram and kilogram or
currency units like dollars or euros), so that they are not concatenated or
joined in a syntactically correct but semantically incorrect way (i.e.,
accidentally concatenating values quoted in dollars and euros from different
subvectors.) This is particularly useful when working with linked open data,
i.e., when joins or concatenations are performed on data arriving from a remote
source.
get_variable_units()
is identical to var_unit()
.
See vignette("defined", package = "dataset")
to use comprehensively
with variable labels, namespaces, units of measures, and machine-independent
permanent variable identifiers.
The unit attribute of a vector constructed with defined
,
or any vector that is enriched with a unit attribute.
The var_unit<-
assignment method allows to add, remove, or overwrite this attribute on a vector
x
. The assignment function returns the x
vector invisibly.
Other defined metadata methods and functions:
defined()
,
var_label()
,
var_namespace()
# The defined vector class and dataset_df support units of measure attributes:
var_unit(iris_dataset$Sepal.Length)
# Normally columns of a data.frame do not have a unit attribute:
var_unit(iris$Sepal.Length)
# You can add them with the assignment function:
var_unit(iris$Sepal.Length) <- "centimeter"
# To remove a unit of measure assign the NULL value:
var_unit(iris$Sepal.Length) <- NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.