gtools (version 3.9.5)

na.replace: Replace Missing Values

Description

Replace missing values

Usage

na.replace(x, replace, ...)

Value

Vector with missing values (NA) replaced by the value of replace.

Arguments

x

vector possibly containing missing (NA) values

replace

either a scalar replacement value, or a function returning a scalar value

...

Optional arguments to be passed to replace

Author

Gregory R. Warnes greg@warnes.net

Details

This is a convenience function that is the same as x[is.na(x)] <- replace

See Also

Examples

Run this code

x <- c(1, 2, 3, NA, 6, 7, 8, NA, NA)

# Replace with a specified value
na.replace(x, "999")

# Replace with the calculated median
na.replace(x, median, na.rm = TRUE)

Run the code above in your browser using DataLab