stat_paste: Rounds and combines up to three numbers into table friendly...

View source: R/pretty_output_functions.R

stat_pasteR Documentation

Rounds and combines up to three numbers into table friendly presentation

Description

Takes in up to 3 numeric values, rounds each to a specified digit amount (if numeric), and then combines them accordingly.

Usage

stat_paste(
  stat1,
  stat2 = NULL,
  stat3 = NULL,
  digits = 0,
  trailing_zeros = TRUE,
  bound_char = c("(", "[", "{", "|"),
  sep = ", ",
  na_str_out = "---",
  suffix = NULL
)

Arguments

stat1

first statistic to be pasted.

stat2

second statistic to be pasted (optional).

stat3

third statistic to be pasted (optional).

digits

positive integer of length 1 between 0 (default) and 14, giving the amount of digits to round to.

trailing_zeros

logical indicating if trailing zeros should included (i.e. 0.100 instead of 0.1). Note is set to TRUE output is a character vector

bound_char

the character to be used between stat1 and stat2/stat3. Available options are '(' (default), '[', '{', and '|'.

sep

the string to be used between stat2 and stat3. The default is ', '.

na_str_out

the character to replace missing values with.

suffix

a character string to add at the end of each stat (i.e. ⁠%⁠ if doing response rates)

Details

One value provided - returns a rounded value or the missing character. Two values - returns stat1 (stat2). e.g., mean (sd) Three values - returns stat1 (stat2, stat3). e.g., estimate (95% lower, 95% upper) or median [min, max]

Currently the method does work with string variables, but of course rounding would not be relevant for strings.

Value

string of combined values

Examples


stat_paste(5.109293)
stat_paste(NA)
stat_paste(5.109293, 2.145)
stat_paste(5.109293, 1.7645, 8.0345)
stat_paste(NA, NA, NA)
stat_paste(5.109, "p < 0.001", digits = 3)
stat_paste(c(rep(5,5),NA),c(1:5,NA),c(1,NA,2,NA,3,NA),bound_char = '[')

library(dplyr)
exampleData_BAMA %>%
group_by(antigen, visitno, group) %>%
summarise(median_min_max = stat_paste(median(magnitude, na.rm = TRUE),
                                        min(magnitude, na.rm = TRUE),
                                        max(magnitude, na.rm = TRUE)),
          .groups = "keep")


FredHutch/VISCfunctions documentation built on Oct. 14, 2024, 11:33 p.m.