R/datexp_missing.R

Defines functions datexp_missing

Documented in datexp_missing

#' Prepare an analysis of missing data by computing their frequencies for each variable.
#' @param x      Dataframe. Table containing the categorical variables to cross.
#' @param keypos Character vector. Names of the variables which should not be evaluated.
#' @return A tibble indicating the proportion of missing values per variable.
#' @importFrom tidyr gather
#' @importFrom dplyr mutate
#' @importFrom tibble as_tibble
#' @export

datexp_missing <- function(x,
                           keypos) {
  #Bind variables
  mising <- "missing"
  variable <- "variable"
  
  x <- as_tibble(x)
  x <- gather(x, variable, missing, -keypos) %>%
    mutate(missing = replace(missing, !is.na(missing), 0)) %>%
    mutate(missing = replace(missing, is.na(missing), 1)) %>%
    mutate(missing = as.numeric(missing))

  return(x)
}
NicolasJBM/datexp documentation built on May 14, 2019, 10:36 a.m.