na.replace | R Documentation |
Replace missing values
na.replace(x, replace, ...)
x |
vector possibly containing missing ( |
replace |
either a scalar replacement value, or a function returning a scalar value |
... |
Optional arguments to be passed to |
This is a convenience function that is the same as x[is.na(x)] <- replace
Vector with missing values (NA
) replaced by the value of
replace
.
Gregory R. Warnes greg@warnes.net
is.na
, na.omit
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.