set_label: Set the "label" attribute of an object

View source: R/labels.R

set_labelR Documentation

Set the "label" attribute of an object

Description

Set the "label" attribute of an object

Copy the label from one variable to another

Usage

set_label(x, value, object = FALSE)

copy_label_from(x, from)

Arguments

x

the variable to label

value

value of the label. If x is a list/data.frame, the labels will all be set recursively. If value is a function, it will be applied to the current labels of x.

object

if x is a list/data.frame, object=TRUE will force setting the labels of the object instead of the children

from

the variable whose label must be copied

Value

An object of the same type as x, with labels

Author(s)

Dan Chaltiel

See Also

get_label(), import_labels(), remove_label()

Examples

library(dplyr)
mtcars %>%
   mutate(mpg2=set_label(mpg, "Miles per gallon"),
          mpg3=mpg %>% copy_label_from(mpg2)) %>%
   crosstable(c(mpg, mpg2, mpg3))
mtcars %>%
   copy_label_from(mtcars2) %>%
   crosstable(c(mpg, vs))
mtcars2 %>% set_label(toupper) %>% get_label()

crosstable documentation built on Nov. 13, 2023, 1:08 a.m.