#' mutates percentages in both decimal and scales::percent format.
#'
#'
#'@param data A dataframe (most likely passed with \code{%>%})
#'@param n A tally() or count() result
#'@return The percentage of \code{n} in decimal and percentage (default one decimal place) format.
mutate_pct <- function(data, n) {
dplyr::mutate(data,
pct = n / sum(n),
pct_formatted = scales::percent(n / sum(n), accuracy = 0.1)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.