R/table_NA.R

Defines functions table_NA

Documented in table_NA

#' Count NA
#'
#' @param x object
#'
#' @return NA and Not count
#' @export
#'
#' @examples
#' a <- c(1,2,3,1,NA,NA)
#' table_NA(a)
table_NA <- function(x){
    name <- paste0(deparse(substitute(x)),collapse = '')
    x <- as.character(x)
    ck <- is.na(x)
    x[!ck] <- 'Not'
    x[ck] <- 'NA'
    cmd <- sprintf("table(%s,useNA = 'ifany')",name)
    exec(paste0(name,'=x'))
    exec(cmd)
}

Try the do package in your browser

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

do documentation built on Aug. 3, 2021, 5:06 p.m.