get_label: Extract Label Attribute From a Labelled Vector

Description Usage Arguments See Also Examples

View source: R/get_label.R

Description

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

Usage

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)

nutterb/labelVector documentation built on Feb. 17, 2020, 9:15 p.m.