R/rm_empty_col.R

Defines functions rm_empty_col

Documented in rm_empty_col

#' @title 
#' Remove empty columns
#' @description 
#' This function removes columns filled with \code{NA} or \code{0} from a dataframe.
#' @details 
#' This function is mainly used inside other functions, to remove optional variables
#' when they are not opted in.
#' 
#' @param x A dataframe
#' 
#' @return a dataframe.
#' 
#' @export
#' 
#' @examples
#' library(forestmangr)
#' library(dplyr)
#' data("exfm15")
#' head(exfm15)
#' 
#' exfm15 %>% 
#' mutate(emptycol=NA) %>% 
#' rm_empty_col
#' 
#' 
#' @author Sollano Rabelo Braga \email{sollanorb@@gmail.com}
rm_empty_col <- function(x){
  dplyr::select_if(x, Negate(function(y){all(y==0|is.na(y))}))
  }

Try the forestmangr package in your browser

Any scripts or data that you put into this service are public.

forestmangr documentation built on Nov. 24, 2023, 1:07 a.m.