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"))

Arguments

.data

data frame

...

tidyselect specification. Default selection: none

fill

value to fill missings

missing_type

character vector. Choose what type of missing to fill. Default is all types. choose from "all", "Na", "NaN", "Inf"

Value

data frame

Examples


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