R/rps.R

# round and preserve sum function
rps <- function( x, digits = 0) {
  up <- 10 ^ digits
  x <- x * up
  y <- floor( x)
  indices <- tail( order( x-y),
                   round( sum( x)) - sum( y))
  y[indices] <- y[indices] + 1
  out <- y / up
  return( out)
}
lhenneman/OpinionReport documentation built on June 8, 2019, 5:59 a.m.