revalids {quest} | R Documentation |
Recode Invalid Values from Data
Description
revalids
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
. revalids
is simply a
vectorized version of revalid
to more easily revalid multiple columns
of a data.frame at the same time.
Usage
revalids(data, vrb.nm, valid, undefined = NA, suffix = "_v")
Arguments
data |
data.frame of data. |
vrb.nm |
character vector of colnames from |
valid |
atomic vector of valid values for the data. Note, the valid values must be the same for each variable. |
undefined |
atomic vector of length 1 specifying what the invalid values should be recoded to. |
suffix |
character vector of length 1 specifying the string to add to the end of the colnames in the return object. |
Value
data.frame of recoded variables where any values not present in
valid
have been recoded to undefined
with colnames specified
by paste0(vrb.nm, suffix)
.
See Also
revalid
valids_test
valid_test
Examples
revalids(data = attitude, vrb.nm = names(attitude),
valid = 25:75) # numeric data
revalids(data = as.data.frame(CO2), vrb.nm = c("Type","Treatment"),
valid = c('Quebec','nonchilled')) # factors