replace_na: Replace missing values

Description Usage Arguments Value See Also Examples

View source: R/replace_na.R

Description

Replace missing values in a data.frame or vector.

Usage

1

Arguments

data

A data.frame or vector.

replace

If data is a data.frame, a named list giving the value to replace NA with for each column. If data is a vector, a single value used for replacement.

...

Additional arguments passed onto methods; not currently used.

Value

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.

See Also

na_if() to replace specified values with a NA.

coalesce() to replace missing values within subsequent vector(s) of value(s).

Examples

1
2
3
4
5
6
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")

poorman documentation built on March 28, 2021, 5:05 p.m.