R/drop_na.R

Defines functions check_na drop_na

Documented in drop_na

#' Drop columns with missing values
#'
#' @param df A dataframe
#' @param thresh
#' @param verbose
#' @export
#' @importFrom inspectdf inspect_na
#' @importFrom tibble as.tibble
#' @importFrom dplyr filter
#' @importFrom magrittr %>%

check_na <- function(df, thresh = 0.95, verbose = T, target = NULL){
  
  # get missingness
  df_na <- inspect_na(df)
  
  # colname with missingness above thresh
  df_na <- df_na %>% filter(pcnt >= thresh * 100)
  names_to_drop <- df_na$col_name

  # invisibly return the result
  return(names_to_drop)
}

drop_na <- function(df, names_to_drop){
  # drop columns and return result
  if(length(names_to_drop) > 0){
    which_drop <- match(names_to_drop, colnames(df))
    df <- df[ , -which_drop]
  }
  invisible(df)
}
alastairrushworth/mlblitz documentation built on Nov. 1, 2019, 9:06 p.m.