View source: R/miscellaneous.R
recode_errors | R Documentation |
Recode a vector of erroneous values for a vector or column(s) in a dataframe
by replacing those values with NA or another common indicator value. Similar
to na_if
but is more flexible, e.g. it can operate on
multiple columns/rows (for data frames), or value indices (for vectors).
recode_errors( data, errors, replacement = NA, rows = NULL, cols = NULL, ind = NULL )
data |
A vector, data frame, tibble, or matrix. |
errors |
A vector of erroneous values to be recoded. |
replacement |
The value you wish to replace all errors with. Default = NA. |
rows |
A vector specifying the rows of the data object for which to replace erroneous values. Default is all rows in data. Use "ind" instead if data is a vector. |
cols |
A vector specifying the columns of the data object for which to replace erroneous values. Default is all columns in data. Use "ind" instead if data is a vector. |
ind |
If data is a vector, this accepts a vector specifying the indices the data object for which to replace erroneous values. Default is all indices in data. Use "rows" &/or "cols" to specify indices to operate upon if data is not a vector. |
Craig P. Hutton, Craig.Hutton@gov.bc.ca
#if (hypothetically) values of 0 & 8 were actually data entry errors in the #mtcars dataset these can easily be recoded as NAs data(mtcars) recode_errors(mtcars, cols = c(8:11), #specify a column number range errors = c(0, 8))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.