Learn R Programming

sjmisc (version 1.0.2)

set_val_labels: Attach value labels to a variable or vector

Description

This function attaches character labels as "value.labels" attribute to a variable or vector "x", resp. to all variables of a data frame if "x" is a data.frame. These value labels will be accessed by functions of the sjPlot package, in order to automatically set values or legend labels.

Usage

set_val_labels(x, labels)

Arguments

x
a variable (vector) or a data frame where labels should be attached. Replaces former value labels.
labels
a character vector of labels that will be attached to x by setting the "labels" or "value.labels" attribute. The length of this character vector must equal the value range of x, i.e. if x ha

Value

  • x with attached value labels; or with removed label-attribute if labels = "".

Details

See 'Details' in get_val_labels

See Also

  • http://www.strengejacke.de/sjPlot/datainit/{sjPlot manual: data initialization}
  • http://www.strengejacke.de/sjPlot/view_spss/{sjPlot manual: inspecting (SPSS imported) data frames}
  • get_val_labels

Examples

Run this code
library(sjPlot)
dummy <- sample(1:4, 40, replace=TRUE)
sjp.frq(dummy)

dummy <- set_val_labels(dummy, c("very low", "low", "mid", "hi"))
sjp.frq(dummy)

Run the code above in your browser using DataLab