powered by
This is a translation of the SQL command NULL_IF. It is useful if you want to convert an annoying value to NA.
NULL_IF
NA
na_if(x, y)
Vector to modify
Value to replace with NA
A modified version of x that replaces any values that are equal to y with NA.
x
y
coalesce() to replace missing values with a specified value.
coalesce()
# NOT RUN { na_if(1:5, 5:1) x <- c(1, -1, 0, 10) 100 / x 100 / na_if(x, 0) y <- c("abc", "def", "", "ghi") na_if(y, "") # }
Run the code above in your browser using DataLab