R/pretty_output_functions.R
stat_paste.Rd
Takes in up to 3 numeric values, rounds each to a specified digit amount (if numeric), and then combines them accordingly.
stat_paste(stat1, stat2 = NULL, stat3 = NULL, digits = 0, trailing_zeros = TRUE, bound_char = c("(", "[", "{", "|"), sep = ", ", na_str_out = "---")
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. |
string of combined values
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.
stat_paste(5.109293)#> [1] "5"stat_paste(NA)#> [1] "---"stat_paste(5.109293, 2.145)#> [1] "5 (2)"stat_paste(5.109293, 1.7645, 8.0345)#> [1] "5 (2, 8)"stat_paste(NA, NA, NA)#> [1] "---"stat_paste(5.109, "p < 0.001", digits = 3)#> [1] "5.109 (p < 0.001)"stat_paste(c(rep(5,5),NA),c(1:5,NA),c(1,NA,2,NA,3,NA),bound_char = '[')#> [1] "5 [1, 1]" "5 [2, ---]" "5 [3, 2]" "5 [4, ---]" "5 [5, 3]" #> [6] "---"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)]#> antigen visit group median_min_max #> 1: C.1086C_V1_V2 Tags 1 1 148 (15, 720) #> 2: Con 6 gp120/B 1 1 661 (16, 2674) #> 3: Con S gp140 CFI 1 1 3070 (121, 13901) #> 4: gp70_C.1086C V1/V2/293F 1 1 597 (20, 3755) #> 5: 1086C_D7gp120.avi/293F 1 2 23676 (1264, 32482) #> 6: A1.con.env03 140 CF 1 2 14764 (668, 29786) #> 7: C.1086C_V1_V2 Tags 1 2 3015 (547, 23037) #> 8: Con S gp140 CFI 1 2 29032 (2383, 32561) #> 9: gp70_C.1086C V1/V2/293F 1 2 16101 (2161, 31759) #> 10: 1086C_D7gp120.avi/293F 1 1 2818 (107, 11130) #> 11: 1086C_D7gp120.avi/293F 2 1 100 (23, 863) #> 12: A1.con.env03 140 CF 2 1 18 (2, 144) #> 13: C.1086C_V1_V2 Tags 2 1 0 (-11, 20) #> 14: Con 6 gp120/B 2 1 18 (5, 217) #> 15: Con S gp140 CFI 2 1 150 (26, 1342) #> 16: gp70_C.1086C V1/V2/293F 2 1 12 (2, 30) #> 17: 1086C_D7gp120.avi/293F 1 3 3789 (2415, 31558) #> 18: C.1086C_V1_V2 Tags 1 3 476 (91, 21307) #> 19: Con 6 gp120/B 1 3 1302 (410, 28791) #> 20: Con S gp140 CFI 1 3 6602 (5111, 31555) #> 21: gp70_C.1086C V1/V2/293F 1 3 2908 (740, 30288) #> 22: 1086C_D7gp120.avi/293F 2 3 2349 (195, 20700) #> 23: A1.con.env03 140 CF 2 3 876 (80, 3043) #> 24: C.1086C_V1_V2 Tags 2 3 209 (9, 1076) #> 25: Con 6 gp120/B 2 3 894 (73, 6106) #> 26: Con S gp140 CFI 2 3 5452 (379, 23167) #> 27: gp70_C.1086C V1/V2/293F 2 3 644 (76, 3150) #> 28: 1086C_D7gp120.avi/293F 2 2 1540 (248, 24204) #> 29: A1.con.env03 140 CF 2 2 461 (88, 18816) #> 30: C.1086C_V1_V2 Tags 2 2 167 (24, 17945) #> 31: Con 6 gp120/B 2 2 331 (44, 7571) #> 32: Con S gp140 CFI 2 2 1487 (305, 24379) #> 33: gp70_C.1086C V1/V2/293F 2 2 874 (200, 24218) #> antigen visit group median_min_max