Learn R Programming

quest (version 0.2.0)

revalid: 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)

Value

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

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.

See Also

revalids valid_test valids_test

Examples

Run this code
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

Run the code above in your browser using DataLab