has_val_labs {labelr}R Documentation

Is This a Value-labeled Variable (Column)?

Description

Determine whether a specific variable of a data.frame has value labels associated with it.

Usage

has_val_labs(data, var, type = "any")

hvl(data, var, type = "any")

Arguments

data

a data.frame.

var

the unquoted name of the variable (column) to check for the presence of value labels.

type

the type of value label to check the variable for: "any," "1to1," "m1," or "q." If "1to1," check will be for value labels added via add_val_labs() or add_val1(). If "m1," check will be for value labels added via add_m1_lab() or add1m1(). If "q," check will be for value labels added via add_quant_labs() or add_quant1(). If "any," will return TRUE if any of the foregoing value label types is found.

Details

hvl is a compact alias for has_val_labs: they do the same thing, and the former is easier to type

Value

A 1L logical.

Examples

# add val labs to multiple variables at once
# make a "Likert"-type fake data set to demo
# note, by default, add_val_labs() "vars" arg will do partial matching
# in this case, we catch all vars with "y" in their name, except "y3"
set.seed(272)
dflik <- make_likert_data(scale = 1:7)
vals2label <- 1:7
labs2use <- c(
  "VSD",
  "SD",
  "D",
  "N",
  "A",
  "SA",
  "VSA"
)

dflik <- add_val_labs(
  data = dflik, vars = c("y"), # note the vars args
  not.vars = "y3",
  vals = vals2label,
  labs = labs2use,
  partial = TRUE
)

has_val_labs(dflik, y1) # TRUE

has_val_labs(dflik, y3) # FALSE, see not.vars arg above

[Package labelr version 0.1.5 Index]