replace_na | R Documentation |
Replace missing values in a data.frame
or vector
.
replace_na(data, replace, ...)
data |
A |
replace |
If |
... |
Additional arguments passed onto methods; not currently used. |
If data
is a data.frame
, replace_na()
returns a data.frame
. If data
is a vector
, replace_na()
returns a
vector
of class determined by the union of data
and replace
.
na_if()
to replace specified values with a NA
.
coalesce()
to replace missing values within subsequent vector
(s) of value(s).
df <- data.frame(x = c(1, 2, NA), y = c("a", NA, "b"), stringsAsFactors = FALSE)
df %>% replace_na(list(x = 0, y = "unknown"))
df %>% mutate(x = replace_na(x, 0))
df$x %>% replace_na(0)
df$y %>% replace_na("unknown")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.