R/na_if.R

Defines functions na_if. na_if

Documented in na_if 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)
}

#' @export
#' @keywords internal
#' @inherit na_if
na_if. <- function(x, y) {
  deprecate_dot_fun()
  na_if(x, y)
}

Try the tidytable package in your browser

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

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.