R/avg_sd_fxn.R

Defines functions avg_sd_fxn

Documented in avg_sd_fxn

#' Get formatted character vector of the average +/- SD. 
#' 
#' @import tidyverse
#' @importFrom stats sd
#' 
#' @export
#' 
#' @param x Numeric Vector
#' @param n.digits number of digits after the decimal point. Default is 1.
#' @param include.n include sample size? Default is false.  
avg_sd_fxn <- function(x, n.digits = 1, include.n = FALSE) {
  out <- paste(round(mean(x, na.rm = T), n.digits) |>
                 formatC(format="f", digits=n.digits),
               round(sd(x, na.rm = T), n.digits) |>
                 formatC(format="f", digits=n.digits), sep = " \u00b1 ") 
  if(include.n == TRUE) {
    out <- paste(out, 
                 " (",
                 paste(length(which(!is.na(x))), ")", sep = ""), 
                 sep = "") }
  return(out)
}
JAGoodrich/jag2 documentation built on May 16, 2024, 12:13 a.m.