R/na_if.R

Defines functions na_if

Documented in na_if

#' Convert values to `NA`
#'
#' @description
#' Convert values to `NA`.
#'
#' @param x A vector
#' @param y Value to replace with `NA`
#'
#' @export
#'
#' @examples
#' vec <- 1:3
#' na_if(vec, 3)
na_if <- function(x, y) {
  size <- vec_size(x)
  y <- vec_recycle(y, size)
  vec_assign(x, x == y, NA)
}
mtfairbanks/gdt documentation built on April 12, 2024, 6:51 p.m.