#' Fill all NA values in numeric columns with zero
#'
#' Any NA values in a column of type numeric will be replaced with a zero.
#'
#' @param .data a tbl or data frame
#'
#' @return An object of the same class as `.data`
#' @export
#'
#' @examples
#' library(dplyr)
#'
#' data_tbl <- tibble(x = c(1, NA_real_, 3), y = c("a", "b", "C"), z = c(7, NA_real_, NA_real_))
#'
#' fill_nas(data_tbl)
fill_nas <- function(.data) {
dplyr::mutate_if(
.tbl = .data,
.predicate = is.numeric,
.funs = ~ dplyr::if_else(is.na(.), 0, .)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.