R/drop_na_cols.R

Defines functions drop_na_cols

Documented in drop_na_cols drop_na_cols

#' Drops columns from the dataframe that meet a certain threshold of NAs.
#'
#' @param df dataframe.  The dataframe to drop from.
#' @param treshold integer.  If a column has this many percent of NAs or more, drop.
#' @export
drop_na_cols <- function(df, threshold = 0.7)
  df[which(sapply(df, function(col) { mean(is.na(col)) < threshold }))]
peterhurford/surveytools2 documentation built on Feb. 18, 2021, 9:13 p.m.