chk-labels {testdat} | R Documentation |
Checks: labels
Description
Check that a vector is labelled in a given way.
Usage
chk_labels(x, val_labels = NULL, var_label = NULL)
Arguments
x |
A vector to check. |
val_labels |
What value label check should be performed? One of:
|
var_label |
What variable label check should be performed? One of:
|
Value
A logical vector flagging records that have passed or failed the check.
See Also
Other vector checks:
chk-dates
,
chk-dummy
,
chk-patterns
,
chk-text
,
chk-uniqueness
,
chk-values
Examples
df <- data.frame(
x = labelled::labelled(c("M", "M", "F"), c(Male = "M", Female = "F"), "Sex"),
y = labelled::labelled(c("M", "M", "F"), c(Male = "M", Female = "F", Other = "X")),
z = c("M", "M", "F")
)
# Check for a value-label pairing
chk_labels(df$x, c(Male = "M"))
# Check that two variables have the same values
chk_labels(df$x, labelled::val_labels(df$y))
# Check for the presence of a particular label
chk_labels(df$x, "Male")
chk_labels(df$x, var_label = "Sex")
# Check that a variable is labelled at all
chk_labels(df$z, val_labels = TRUE)
chk_labels(df$z, var_label = TRUE)
# Check that a variable isn't labelled
chk_labels(df$z, val_labels = FALSE)
chk_labels(df$z, var_label = FALSE)