revalid {quest} | R Documentation |
Recode Invalid Values from a Vector
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
revalid(x, valid, undefined = NA)
Arguments
x |
atomic vector. |
valid |
atomic vector of valid values for |
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
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
[Package quest version 0.2.0 Index]