The defined
constructor creates the objects of this class, which
are semantically extended vectors inherited from
haven::labelled
.
Usage
defined(
x,
labels = NULL,
label = NULL,
unit = NULL,
definition = NULL,
namespace = NULL
)
is.defined(x)
# S3 method for class 'haven_labelled_defined'
as.character(x, ...)
# S3 method for class 'haven_labelled_defined'
summary(object, ...)
Arguments
- x
A vector to label. Must be either numeric (integer or double) or character.
- labels
A named vector or
NULL
. The vector should be the same type asx
. Unlike factors, labels don't need to be exhaustive: only a fraction of the values might be labelled.- label
A short, human-readable description of the vector or
NULL
.- unit
A character string of length one containing the unit of measure or
NULL
.- definition
A character string of length one containing a linked definition or
NULL
.- namespace
A namespace for individual observations or categories or
NULL
.- ...
Further parameters for inheritance, not in use.
- object
An R object to be summarised.
Value
The constructor defined
returns a vector with defined
value labels, a variable label, an optional unit of measurement and linked
definition.is.defined
returns a logical value, stateing if the object is of
class defined
.
Details
as.character
coerces a defined vector into a character vector.summary
summarises the defined
vector.
For more details, please check the vignette("defined", package = "dataset")
vignette.
See also
Other defined metadata methods and functions:
var_label()
,
var_namespace()
,
var_unit()
Examples
gdp_vector <- defined(
c(3897, 7365, 6753),
label = "Gross Domestic Product",
unit = "million dollars",
definition = "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)
#> <haven_labelled_defined[3]>: Gross Domestic Product
#> [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]
#> <haven_labelled_defined[2]>: Gross Domestic Product
#> [1] 3897 7365