Learn R Programming

sjmisc (version 1.5)

get_values: Retrieve values of labelled variables

Description

This function retrieves the values associated with value labels of an imported SPSS, SAS or STATA data set (via read_spss, read_sas or read_stata), or of a labelled vector.

Usage

get_values(x, sort.val = FALSE, drop.na = FALSE)

Arguments

x
Variable (vector) with value label attributes.
sort.val
Logical, if TRUE (default), values of associated value labels are sorted.
drop.na
Logical, if TRUE, missing code values are excluded from the return value. See 'Examples' and get_na.

Value

  • The values associated with value labels from x, or NULL if x has no label attributes.

Details

labelled vectors are numeric by default (when imported with read-functions like read_spss) and have variable and value labels attributes. The value labels are associated with those values from the labelled vector. This function returns the values associated with the vector's value labels, which may differ from actual values in the vector (e.g. due to missings) or are not represented in sorted order.

See Also

get_labels for getting value labels and get_na to get values for missing values.

Examples

Run this code
data(efc)
str(efc$e42dep)
get_values(efc$e42dep)
get_labels(efc$e42dep)

# create labelled integer, with missing flag
x <- labelled(c(1, 2, 1, 3, 4, 1),
              c(Male = 1, Female = 2, Refused = 3, "N/A" = 4),
              c(FALSE, FALSE, TRUE, TRUE))
# get all values
get_values(x)
# drop NA
get_values(x, , TRUE)

Run the code above in your browser using DataLab