DescTools (version 0.99.18)

ZeroIfNA: Replace NAs by 0

Description

Replace NAs in a vector x with 0. This function has the same logic as the zeroifnull function in SQL.

Usage

ZeroIfNA(x)
Impute(x, FUN = function(x) median(x, na.rm = TRUE))

Arguments

x
the vector x, whose NAs should be overwritten with 0s.

FUN
the name of a function to be used as imputation. Can as well be a self defined function or a constant value. Default is median.

Value

See Also

replace

Examples

Run this code
z <- c(8, NA, 9, NA, 3)

ZeroIfNA(z)
# [1] 8 0 9 0 3

Impute(z)
# [1] 8 8 9 8 3


Run the code above in your browser using DataCamp Workspace