var_label: Get / Set a variable label

Description Usage Arguments Details Value Note Examples

View source: R/var_label.R

Description

Get / Set a variable label

Usage

1
2
3
4
5

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)

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.

Value

set_variable_labels will return an updated copy of .data.

Note

set_variable_labels could be used with dplyr.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
var_label(iris$Sepal.Length)
var_label(iris$Sepal.Length) <- 'Length of the sepal'
## Not run: 
 View(iris)

## End(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)
}

labelled documentation built on May 25, 2018, 1:03 a.m.