labelled (version 2.0.2)

var_label: Get / Set a variable label

Description

Get / Set a variable label

Usage

var_label(x)

var_label(x) <- value

set_variable_labels(.data, ...)

Arguments

x

An object.

value

A character string or NULL to remove the label. For data frames, it could also be a named list.

.data

a data frame

...

name-value pairs of variable labels (see examples)

Value

set_variable_labels will return an updated copy of .data.

Details

For data frames, if value is a named list, only elements whose name will match a column of the data frame will be taken into account.

Examples

Run this code
# NOT RUN {
var_label(iris$Sepal.Length)
var_label(iris$Sepal.Length) <- 'Length of the sepal'
# }
# NOT RUN {
 View(iris)
# }
# NOT RUN {
# To remove a variable label
var_label(iris$Sepal.Length) <- NULL
if (require(dplyr)) {
  # adding some variable labels
  df <- data_frame(s1 = c("M", "M", "F"), s2 = c(1, 1, 2)) %>%
    set_variable_labels(s1 = "Sex", s2 = "Yes or No?")
  var_label(df)

  # removing a variable label
  df <- df %>% set_variable_labels(s2 = NULL)
  var_label(df$s2)
}
# }

Run the code above in your browser using DataCamp Workspace