Learn R Programming

sjmisc (version 1.0.0)

get_val_labels: Retrieve value labels of a variable or an SPSS-imported data frame

Description

This function retrieves the value labels of an imported SPSS data set (via read_spss) and
  • ifxis a data frame, returns the all variable's value labels aslistobject
  • or, ifxis a vector, returns the label as string.

Usage

get_val_labels(x)

Arguments

x
a data frame with variables that have attached value labels (e.g. from an imported SPSS data (see read_spss)) or a variable (vector) with attached value labels.

Value

  • Either a list with all value labels from the data frame's variables, a string with the value labels, if x is a variable, or NULL if no value label attribute was found.

Details

This package can add (and read) value and variable labels either in foreign package style (value.labels and variable.label) or in haven package style (labels and label). By default, the haven package style is used. The sjPlot package accesses these attributes to automatically read label attributes for labelling axes categories and titles or table rows and columns. Furthermore, value and variable labels are used when saving data, e.g. to SPSS (see write_spss), which means that the written SPSS file contains proper labels for each variable. You can set a default label style via options(value_labels = "haven") or options(value_labels = "foreign").

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}
  • set_val_labels

Examples

Run this code
# import SPSS data set
# mydat <- read_spss("my_spss_data.sav", enc="UTF-8")

# retrieve variable labels
# mydat.var <- get_var_labels(mydat)

# retrieve value labels
# mydat.val <- get_val_labels(mydat)

data(efc)
get_val_labels(efc$e42dep)

Run the code above in your browser using DataLab