valid_test {quest}R Documentation

Test for Invalid Elements in a Vector

Description

valid_test tests whether a vector has any invalid elements. Valid values are specified by valid. If the vector x has any values other than valid, then FALSE is returned; If the vector x only has values in valid, then TRUE is returned. This function can be useful for checking data after manual human entry.

Usage

valid_test(x, valid, na.rm = TRUE)

Arguments

x

atomic vector or list vector.

valid

atomic vector or list vector of valid values.

na.rm

logical vector of length 1 specifying whether NA should be ignored from the validity test. If TRUE (default), then any NAs are treated as valid.

Value

logical vector of length 1 specifying whether all elements in x are valid values. If FALSE, then (at least one) invalid values are present.

See Also

valids_test revalid revalids

Examples

valid_test(x = psych::bfi[[1]], valid = 1:6) # return TRUE
valid_test(x = psych::bfi[[1]], valid = 0:5) # 6 is not present in `valid`
valid_test(x = psych::bfi[[1]], valid = 1:6,
   na.rm = FALSE) # NA is not present in `valid`

[Package quest version 0.2.0 Index]