R/predict.binR.r

Defines functions predict.binR

Documented in predict.binR

# vim: shiftwidth=2 tabstop=2
##------------------------------------------------------------------------------
#' Predict binR
#' 
#' Apply binning defined in binR object to new dataset
#' 
#' 
#' @param obj binR object
#' @param newdata the new data.frame to bin
#' @return a data.frame with the binned objects
#' 
#' @export
##------------------------------------------------------------------------------
predict.binR <- function(obj, newdata) {
  fx <- as.formula(paste('~',paste(obj$vars, collapse="+")))
  mframe <- model.frame(fx, newdata)

  out <- foreach(d=obj$vars, .combine=data.frame, .multicombine=T) %dopar% {
    cut(mframe[ ,d], breaks=obj$breaks[[d]])
  }
  names(out) <- obj$vars
  out
}
while/binR documentation built on May 4, 2019, 5:23 a.m.