R/fill.R

Defines functions fill_value

Documented in fill_value

#' fill missing value
#'
#' Returns a vector with all missing values filled with another value
#' @param x vectors. All inputs should have the same length
#' @param value a value with the same class as x
#' @return vector with the same length as the first vector
#' @export
#'
#' @examples
#' fill_value(c(NA,1), 2)
fill_value <- function(x, value) {
  stopifnot(length(value) == 1)
  stopifnot(class(x) == class(value))
  i <- which(is.na(x))
  x[i] <- value
  return(x)
}

Try the vvfiller package in your browser

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

vvfiller documentation built on Feb. 16, 2023, 6:55 p.m.