#' 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.