replace_na

0th

Percentile

Replace missing values

Replace missing values

Usage
replace_na(data, replace = list(), ...)
Arguments
data

A data frame.

replace

A named list given the value to replace NA with for each column.

...

Additional arguments for methods. Currently unused.

Aliases
  • replace_na
Examples
# NOT RUN {
library(dplyr)
df <- data_frame(x = c(1, 2, NA), y = c("a", NA, "b"))
df %>% replace_na(list(x = 0, y = "unknown"))
# }
Documentation reproduced from package tidyr, version 0.6.3, License: MIT + file LICENSE

Community examples

772927148@qq.com at Nov 1, 2019 tidyr v0.8.3

library(dplyr) df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"), z = list(1:5, NULL, 10:20)) df %>% replace_na(list(x = 0, y = "unknown")) df %>% mutate(x = replace_na(x, 0)) df %>% replace_na(list(z = list(5))) df$x %>% replace_na(0) df$y %>% replace_na("unknown")

prabhakaran.mails@gmail.com at Aug 19, 2019 tidyr v0.8.3

#### To Replace NAs in all the columns of the dataframe ``` set.seed(2) x=c(1,2,3,NA) df = data.frame(col_1 = sample(x,15,replace = TRUE),col_2=sample(x,15,replace = TRUE)) df %>% mutate_if(is.numeric,list(~replace_na(.,0))) df %>% mutate_all(list(~replace_na(.,0))) ```