R/misc.R

Defines functions round_rand

#' @importFrom plyr round_any
round_rand = function(x, accuracy = 1) {
  prob = (x - plyr::round_any(x, accuracy, f = floor)) / accuracy
  return(ifelse(runif(length(x)) < prob,
                plyr::round_any(x, accuracy, f = ceiling),
                plyr::round_any(x, accuracy, f = floor)))
  }
noamross/spore documentation built on May 23, 2019, 9:31 p.m.