#' Round percent
#'
#' Round percentages to get a whole integer
#' @param x A numeric vector
#' @return A numeric vector
#' @export
round_percent <- function(x) {
x <- x/sum(x)*100 # Standardize result
res <- floor(x) # Find integer bits
rsum <- sum(res) # Find out how much we are missing
if(rsum<100) {
# Distribute points based on remainders and a random tie breaker
o <- order(x%%1, sample(length(x)), decreasing=TRUE)
res[o[1:(100-rsum)]] <- res[o[1:(100-rsum)]]+1
}
res
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.