Learn R Programming

dataset (version 0.3.4)

defined: Create a semantically well-defined, labelled vector

Description

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 haven_labelled_defined as.character(x, ...)

# S3 method for haven_labelled_defined summary(object, ...)

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.

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 as x. 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.

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

Run this code

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)

 # To print the defined vector:
 print(gdp_vector)

 # To summarise the defined vector:
 summary(gdp_vector)

 # Subsetting work as expected:
 gdp_vector[1:2]

Run the code above in your browser using DataLab