revalid: Recode Invalid Values from a Vector

Description Usage Arguments Value See Also Examples

View source: R/quest_functions.R

Description

revalid recodes invalid data to specified values. For example, sometimes invalid values are present in a vector of data (e.g., age = -1). This function allows you to specify which values are possible and will then recode any impossible values to undefined. This function is a useful wrapper for the function car::recode, tailored for the specific use of recoding invalid values.

Usage

1
revalid(x, valid, undefined = NA)

Arguments

x

atomic vector.

valid

atomic vector of valid values for x.

undefined

atomic vector of length 1 specifying what the invalid values should be recoded to.

Value

atomic vector with the same typeof as x where any values not present in valid have been recoded to undefined.

See Also

revalids valid_test valids_test

Examples

1
2
3
4
5
revalid(x = attitude[[1]], valid = 25:75, undefined = NA) # numeric vector
revalid(x = as.character(ToothGrowth[["supp"]]), valid = c('VC'),
   undefined = NA) # character vector
revalid(x = ToothGrowth[["supp"]], valid = c('VC'),
   undefined = NA) # factor

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to revalid in quest...