View source: R/quest_functions.R
revalid | R Documentation |
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.
revalid(x, valid, undefined = NA)
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. |
atomic vector with the same typeof as x
where any values not
present in valid
have been recoded to undefined
.
revalids
valid_test
valids_test
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.