Learn R Programming

sjmisc (version 1.0.2)

get_var_labels: Retrieve variable labels of a data frame or a variable

Description

This function retrieves the value labels of an imported SPSS, SAS or STATA data set (via read_spss, read_sas or read_stata) and
  • ifxis a data frame, returns the all variable labels as names character vector of lengthncol(x).
  • or, ifxis a vector, returns the variable label as string.

Usage

get_var_labels(x)

Arguments

x
A data frame or a vector with "label" or "variable.label" attribute.

Value

  • A named char vector with all variable labels from the data frame, or a simple char vector (of length 1) with the variable label, if x is a variable.

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}
  • set_var_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 variable lable
get_var_labels(efc$e42dep)

# alternative way
get_var_labels(efc)["e42dep"]

# simple barplot
barplot(table(efc$e42dep))
# get value labels to annotate barplot
barplot(table(efc$e42dep),
        names.arg = get_val_labels(efc$e42dep),
        main = get_var_labels(efc$e42dep))

Run the code above in your browser using DataLab