R/na_which.R

Defines functions which_na na_which_data.frame na_which.default na_which

Documented in na_which na_which_data.frame na_which.default which_na

#' na_which: Identify missing values
#' 
#' Return the indexes of those values that are missing 
#' 
#' @param x Vector to search for missing values
#' 
#' @details 
#' 
#' Implemented as . %>% is.na %>% which 
#' 
#' For data.frames: 
#' 
#' @return \code{integer} of indexes of \code{x} that are \code{NA}.  The
#' \code{names} of the returned vector are set to the names of \code{x}.
#' that are \code{NA}.
#' 
#' @examples
#'   x <- c( 1, NA, NA, 3:6 )
#'   na_which(x)
#' @rdname na_which
#' @export na_which

na_which <- function(x) UseMethod('na_which') 


#' @rdname na_which
#' @export
na_which.default <- function(x)
  which( is.na(x) )


#' @rdname na_which
#' @export
na_which_data.frame <- function(x)
  names(x)[ sapply( x, anyNA ) ]

#' @rdname na_which
#' @export

which_na <- function(x) {
 message("which_na is deprecated. Use na_which instead.") 
 na_which(x) 
}
decisionpatterns/na.actions documentation built on Aug. 25, 2020, 8:04 p.m.