R/step_quantile.R

#'@export
step_quantile <- function(x, start, stop, p){
  stopifnot(length(start)==length(stop))
  stopifnot(length(stop)==length(p))
  cdf <- cumsum(p)
  q <- sapply(x, FUN=function(xx){
    ix <- min(which(cdf > xx))
    if(ix==1) res <- xx
      else res <- xx-cdf[ix-1]
    (res/p[ix])*(stop[ix]-start[ix]) + start[ix]
  })
  return(q)
}
jean997/sherlockAsh documentation built on May 18, 2019, 11:45 p.m.