val_lab: Set or get value labels

Description Usage Arguments Details Value Examples

View source: R/labels.R

Description

These functions set/get/drop value labels. Duplicated values are not allowed. If argument x is data.frame or list then labels applied to all elements of data.frame/list. To drop value labels, use val_lab(var) <- NULL or unvl(var). For variable labels see var_lab.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
val_lab(x)

val_lab(x) <- value

set_val_lab(x, value, add = FALSE)

add_val_lab(x, value)

has.labels(x)

add_val_lab(x) <- value

unvl(x)

drop_val_labs(x)

drop_unused_labels(x)

Arguments

x

Variable(s). Vector/data.frame/list.

value

Named vector. Names of vector are labels for the appropriate values of variable x.

add

Logical. Should we add value labels to old labels or replace it? Deafult is FALSE - we completely replace old values. If TRUE new value labels will be combined with old value labels.

Details

Value labels are stored in attribute "labels" (attr(x,"labels")). We set variable class to "labelled" for preserving labels from dropping during some operations (such as c and `[`).

Value

val_lab return value labels (named vector). If labels doesn't exist it return NULL . val_lab<- and set_val_lab return variable (vector x) of class "labelled" with attribute "labels" which contains value labels.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# toy example
set.seed(123)
# score - evaluation of tested product

score = sample(-1:1,20,replace = TRUE)
var_lab(score) = "Evaluation of tested brand"
val_lab(score) = c("Dislike it" = -1,
                   "So-so" = 0,
                   "Like it" = 1
                   )

adayim/cctab documentation built on Dec. 18, 2021, 10:26 p.m.