R/discrete_mode.R

discrete_mode <- function(x) {
  
  condition <- is.factor(x)
  if(condition) {
    
    x_levels <- levels(x)
    x_probability <- m_estimator(x)
    x_maximum <- which_maximum(x_probability)
    x_mode <- factor(x_levels[x_maximum], levels = x_levels)
    
    # return
    rout <- x_mode
    return(rout)
    
  } else {
    stop("x MUST be a factor.")
  }
  
}
dsnavega/imputeForest documentation built on May 8, 2019, 2:43 p.m.