ifna: Missingness Coalescing Operator

Description Usage Arguments Details References Examples

Description

Substitutes values when NA is detected.

Usage

1
ifna(x, y)

Arguments

x

An possibly containing NA values

y

An object of equal length or a single value to be used in substitution

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 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)

# Replace NA with 5
ifna(x, 5)

coatless/rops documentation built on May 13, 2019, 8:47 p.m.