install logo correctly
This commit is contained in:
@@ -8,33 +8,38 @@
|
||||
#'
|
||||
#' @examples
|
||||
#' safe_max(1:10)
|
||||
#' safe_max(c(1:10, NA)) # 10
|
||||
#' safe_max(c(1:10, NA))# 10
|
||||
safe_max <- function(x) {
|
||||
max(x, na.rm = TRUE)
|
||||
if (all(is.na(x))) {
|
||||
return(NA)
|
||||
} else {
|
||||
max(x, na.rm = TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#' Prettify proportion data
|
||||
#' Make data expresed as proportions print out as prettily formatted characters with percentages
|
||||
#'
|
||||
#' @param x a numeric vector of proportions to convert to percentages
|
||||
#' @param ndigit a vector of length 1 indicating the number of digits to display in the percent
|
||||
#' @param ndigit a vector of length 1 indicating the number of digits to display in the percent, by
|
||||
#' default it represents the digits after the decimal point in the percentage form
|
||||
#'
|
||||
#' @return
|
||||
#' @return a character vector with a % attached
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' pretty_per(0.2, ndigit = 1)
|
||||
#' pretty_per(c(0.2, 0.332423, 0.4, 0.342342), ndigit = 2)
|
||||
pretty_per <- function(x, ndigit = 1) {
|
||||
x <- format(round(x, digits = 3) * 100, nsmall = ndigit)
|
||||
if (any(x >= 100) & !all(is.na(x))) {
|
||||
message("Values over 100 found, did you mean to use proportions?")
|
||||
}
|
||||
x <- format(round(x, digits = ndigit + 2) * 100, nsmall = ndigit)
|
||||
x <- paste0(x, "%")
|
||||
x[x == "NA%"] <- " - "
|
||||
x <- trimws(x)
|
||||
return(x)
|
||||
}
|
||||
options(knitr.kable.NA = "-")
|
||||
|
||||
|
||||
#' Zero out missing values
|
||||
|
||||
Reference in New Issue
Block a user