R/nested_missing_table.R

Defines functions nested_missing_table

Documented in nested_missing_table

#' Tabulate Nested Missing Data
#'
#' @description This function tabulates nested missing data using a slightly altered (for presentation) version of
#' \code{\link[naniar]{miss_var_summary}}.
#' @inheritParams plot_nested_missing
#' @return A dataframe summarising missing data
#' @export
#' @importFrom naniar miss_var_summary
#' @importFrom dplyr mutate select
#' @importFrom prettypublisher pretty_round
#' @examples
#'
#' ## Code
#' nested_missing_table
nested_missing_table <- function(df) {

  pct_miss <- NULL; Variable <- NULL; variable <- NULL;
  missing <- NULL; percent <- NULL; reported <- NULL;
  n_miss <- NULL;

  df %>%
    miss_var_summary %>%
    dplyr::mutate(percent = pretty_round(pct_miss, digits = 1),
                  reported = paste0(percent, " (", n_miss, ")")) %>%
    dplyr::select(variable, percent, n_miss, reported)
}
seabbs/ETSMissing documentation built on Nov. 22, 2019, 5:08 p.m.