📜  dplyr replace na - R 编程语言代码示例

📅  最后修改于: 2022-03-11 14:51:59.998000             🧑  作者: Mango

代码示例1
df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))

df %>% dplyr::mutate(x = replace_na(x, 0))
#> # A tibble: 3 x 2
#>       x y    
#>    
#> 1     1 a    
#> 2     2 NA   
#> 3     0 b

# To replace NA in two columns
df %>% replace_na(list(x = 0, y = "unknown"))
#> # A tibble: 3 x 2
#>       x y      
#>      
#> 1     1 a      
#> 2     2 unknown
#> 3     0 b