R/nona.R

Defines functions nona

Documented in nona

#' No NAs
#'
#' Converts NAs to 0s
#' @param vec Required. Character or Numeric vector. 
#' @return Character vector.
#' @export
#' @importFrom checkmate assert
#' @examples
#' x <- c(NA, 1, 0); nona(x)
#' x <- c(NA, "dk", 0); nona(x)

nona <- function(vec = NULL) {
  
  assert(
    !is.null(vec),
    .var.name = "vec",
    info = "Input vector cannot be NULL"
  )
  
  vec[is.na(vec)] <- 0
  vec
}

Try the guess package in your browser

Any scripts or data that you put into this service are public.

guess documentation built on March 31, 2026, 9:07 a.m.