get_label {labelVector}R Documentation

Extract Label Attribute From a Labelled Vector

Description

Retrieve the label attribute of a labelled vector. If the vector has no label, the vector name is returned as a string.

Usage

get_label(x, ...)

## Default S3 method:
get_label(x, ...)

## S3 method for class 'data.frame'
get_label(x, vars = NULL, ..., return_vector = TRUE)

Arguments

x

An atomic vector.

...

Arguments to pass to other methods.

vars

A character vector of variable names in x for which to retrieve labels. If NULL, all labels are returned.

return_vector

logical. When TRUE, a vector of the variables is returned. Otherwise, a named list mapping variable names to labels is returned. The named list can be useful for restoring labels after various transformations that may drop attributes.

See Also

set_label

Examples

x <- 1:10
x <- set_label(x, "Integers")

get_label(x)

y <- letters
attr(y, "label")    # NULL
get_label(y)        # "y"

# Set labels for variables in a data frame

mtcars2 <-
  set_label(mtcars,
            am = "Automatic / Manual",
            mpg = "Miles per Gallon",
            gear = "Number of gears")

get_label(mtcars2)


[Package labelVector version 0.1.2 Index]