Substitutes values when NA
is detected.
Details
The objective of this function is to provide an ability to substitute values
for NA. However, it is important to note that R is unique in the fact
that it has an NA
data type to represent missingness instead of relying
on values being pre-coded (e.g. 0
, -1111
, et cetera). Thus, the simplicity
of this function comes with the disclaimer of:
"An NA is the presence of an absence. Don't forget that some missing values are the absence of a presence"
Hadley Wickham on Twitter
References
https://support.office.com/en-us/article/IFNA-function-6626c961-a569-42fc-a49d-79b4951fd461
Examples
# Data with missing values
x <- c(1, NA, NA, 4)
# Substitution vector of equal length
y <- 1:4
# Replace NA with values in `y` vector
ifna(x, y)
#> [1] 1 2 3 4
# Replace NA with 5
ifna(x, 5)
#> [1] 1 5 5 4