R/replace_na_with_zero.R

Defines functions replace_na_with_zero

Documented in replace_na_with_zero

#' Replace NA with zero
#' @param data data.frame
#' 
replace_na_with_zero <- function(data) {
  
  num_col <- sapply(data, is.numeric)
  
  from_na_to_zero <- function(x) {
    
    ifelse(is.na(x), 0, x)
    
  }
  
  data[, num_col] <- sapply(data[, num_col], from_na_to_zero)
  
  return(data)
  
}
kristian-bak/rumination documentation built on Oct. 31, 2022, 6:44 p.m.