use tidyselect to fill NA
values
Default behavior is to fill all integer or double columns cols with 0, preserving their types.
fill_na(.data, ..., fill = 0L, missing_type = c("all", "NA", "NaN", "Inf"))
data frame
tidyselect specification. Default selection: none
value to fill missings
character vector. Choose what type of missing to fill. Default is all types. choose from "all", "Na", "NaN", "Inf"
data frame
tibble::tibble(x = c(NA, 1L, 2L, NA, NaN, 5L, Inf)) -> tbl
tbl %>%
fill_na()
#> # A tibble: 7 × 1
#> x
#> <dbl>
#> 1 0
#> 2 1
#> 3 2
#> 4 0
#> 5 0
#> 6 5
#> 7 0
tbl %>%
fill_na(fill = 1L, missing_type = "Inf")
#> # A tibble: 7 × 1
#> x
#> <dbl>
#> 1 NA
#> 2 1
#> 3 2
#> 4 NA
#> 5 NaN
#> 6 5
#> 7 1
tbl %>%
fill_na(missing_type = "NaN")
#> # A tibble: 7 × 1
#> x
#> <dbl>
#> 1 NA
#> 2 1
#> 3 2
#> 4 NA
#> 5 0
#> 6 5
#> 7 Inf