Skip to contents

[Stable]

This function manipulates labels. It supports different classes of objects, including default objects, data frames, and other types.

Usage

label(x, label = NULL)

Arguments

x

The object to which the label will be added or modified.

label

A character string specifying the label to be assigned to the variable.

Value

The modified object with the updated label.

Details

When used with dplyr's [mutate] function, this function allows for easy labeling of variables within a data frame.

If used with a data frame, the function labels the dataset itself, and the label can be checked using the [codebook] function.

Examples


library(dplyr)

iris |>
   mutate(Species = label(Species, 'Species of iris flower')) |>
   codebook()
#> $ Codebook
#>   dataset: mutate(iris, Species = label(Species, "Species of iris flower"))
#>   Row: 150
#>   Col: 5
#>   name         type  miss complete unique label                 
#> 1 Sepal.Length <dbl> 0    1.00     35                           
#> 2 Sepal.Width  <dbl> 0    1.00     23                           
#> 3 Petal.Length <dbl> 0    1.00     43                           
#> 4 Petal.Width  <dbl> 0    1.00     22                           
#> 5 Species      <fct> 0    1.00      3     Species of iris flower

iris |>
   label("Iris dataset") |>
   codebook()
#> $ Codebook
#>   dataset: label(iris, "Iris dataset")
#>   label: Iris dataset
#>   Row: 150
#>   Col: 5
#>   name         type  miss complete unique label
#> 1 Sepal.Length <dbl> 0    1.00     35          
#> 2 Sepal.Width  <dbl> 0    1.00     23          
#> 3 Petal.Length <dbl> 0    1.00     43          
#> 4 Petal.Width  <dbl> 0    1.00     22          
#> 5 Species      <fct> 0    1.00      3