Washes the data by replacing values with either NA's or other values set by the user. Useful for replacing values such as 777's or 999's that represent missing values in survey research. Can also perform many useful functions on factors (e.g., removing a level, replacing a level, etc.)

washer(x, ..., value = NA)

Arguments

x

the variable to have values adjusted

...

the values in the variable that are to be replaced by either NA's or the value set by the user. Can be a function (or multiple functions) to specify values to change (e.g., is.nan(), is.na()).

value

(optional) if specified, the values in ... will be replaced by this value (must be a single value)

Value

the original vector (although if the original was a factor, it was changed to a character) with the values changed where indicated.

Examples

x = c(1:20, NA, NaN)
washer(x, 9, 10)
#>  [1]   1   2   3   4   5   6   7   8  NA  NA  11  12  13  14  15  16  17  18  19
#> [20]  20  NA NaN
washer(x, 9, 10, value=0)
#>  [1]   1   2   3   4   5   6   7   8   0   0  11  12  13  14  15  16  17  18  19
#> [20]  20  NA NaN
washer(x, 1:10)
#>  [1]  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  11  12  13  14  15  16  17  18  19
#> [20]  20  NA NaN
washer(x, is.na, is.nan, value=0)
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  0  0
washer(x, is.na, is.nan, 1:3, value=0)
#>  [1]  0  0  0  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  0  0