Learn R Programming

sjPlot (version 1.7)

get_var_labels: Retrieve variable labels of (an SPSS-imported) data frame or of a specific variable

Description

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

Usage

get_var_labels(x)

Arguments

Value

A named char vector with all variable labels from the SPSS dataset, or a simple string vector with the variable label, if x is a variable.

See Also

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)
# sample data set has not attached variable labels to each vector
# so we have to do this first... use 'autoAttachVarLabels' in
# function 'read_spss' to automatically perform this step.
efc <- set_var_labels(efc, get_var_labels(efc))

# get variable lable
get_var_labels(efc$e42dep)

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

Run the code above in your browser using DataLab