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)
Run the code above in your browser using DataLab