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)
}

Try the tidytable package in your browser

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

tidytable documentation built on Sept. 11, 2024, 8:05 p.m.