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

Description Usage Arguments Details Value Examples

Description

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

Usage

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

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.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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(data.table)
data(testData_BAMA)
testData_BAMA [!is.na(magnitude), .(
  median_min_max = stat_paste(
     median(magnitude), min(magnitude), max(magnitude)
     )), by = .(antigen, visit, group)]

wfulp/MoffittFunctions documentation built on May 24, 2019, 11:44 p.m.