8bit-pixies / binst

Bin Stuff - a binning library for R/Python
https://cran.r-project.org/web/packages/binst/
2 stars 1 forks source link

Improve NA support #11

Closed 8bit-pixies closed 8 years ago

8bit-pixies commented 8 years ago

Shouldn't have to do something like complete cases before finding breaks.

8bit-pixies commented 8 years ago

code sketch based on current code.

create_breaks <- function(x, y=NULL, method="kmeans", control=NULL) {
  # test if x or y have NA's and throw a warning
  complete <- complete.cases(x) & complete.cases(y)
  x <- x[complete]
  y <- y[complete]

  method <- tolower(method)
  if (method == "kmeans") {
    return(create_kmeansbreaks(x, control=control))
  }
  if (method %in% c("mdlp", "entropy")) {
    return(create_mdlpbreaks(x, y))
  }
  if (method %in% c("decisiontrees", "dt", "ctrees")) {
    return(create_dtbreaks(x, y, control=control))
  }
  if (method == "jenks") {
    return(create_jenksbreaks(x, control=control))
  }
}