Learn R Programming

crosstable (version 0.8.0)

set_label: 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)

Value

An object of the same type as x, with labels

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

Author

Dan Chaltiel

See Also

get_label(), import_labels(), remove_label()

Examples

Run this code
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()

Run the code above in your browser using DataLab