Learn R Programming

formatters (version 0.5.11)

var_labels<-: Set label attributes of all variables in a data.frame

Description

Variable labels can be stored as the label attribute for each variable. This functions sets all non-missing (non-NA) variable labels in a data.frame.

Usage

var_labels(x) <- value

Value

x with modified variable labels.

Arguments

x

(data.frame)
a data frame object.

value

(character)
a vector of new variable labels. If any values are NA, the label for that variable is removed.

Examples

Run this code
x <- iris
var_labels(x)
var_labels(x) <- paste("label for", names(iris))
var_labels(x)

if (interactive()) {
  View(x) # in RStudio data viewer labels are displayed
}

Run the code above in your browser using DataLab