#' Investigate missingness
#'
#' @param x a vector with multiple elements
#'
#' @details These functions return the number of NA, NaN, or blank values in a
#' vector. Such information can serve as a diagnostic or used outright, e.g.
#' in longitudinal settings. If you are dealing with singletons, you should
#' just use the underlying function, e.g. is.na. For total blank values, the
#' stringi package is required.
#'
#' For more in this realm, I suggest you visit
#' \href{http://naniar.njtierney.com/}{naniar}.
#'
#' @return The number of non-elements so defined
#'
#' @examples
#' library(tidyext)
#' sum_blank(c(' ', '', 'c', 'd'))
#' sum_NA(c(NA, '', 'c', NA))
#' sum_NaN(c(1:3, NA, NaN))
#' sum_NA(1:4)
#'
#'
#'
#' @export
sum_NA <- function(x) {
sum(is.na(x))
}
#' @rdname sum_NA
#' @export
sum_NaN <- function(x) {
if (!is.numeric(x))
stop('x must potentially be a number, in order to not be a number.
~ The Buddha')
sum(is.nan(x))
}
#' @rdname sum_NA
#' @export
sum_blank <- function(x) {
sum(stringi::stri_trim_both(x) == '')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.