tableone icon indicating copy to clipboard operation
tableone copied to clipboard

Vertically align digits on the decimal point?

Open welshpf opened this issue 4 years ago • 1 comments

Hi Mr. Yoshida,

Thank you and your colleagues for creating a great resource for all of us to benefit from! My issue is not so much an issue as a functionality question. Is there was a way to vertically align digits on the decimal point using the print(CreateTableOne) function? I get that sending print(CreateTableOne) creates a matrix object, but I'm not sure how to align those digits in R. Any advice or suggestions would be greatly appreciated.

repro<-structure(c("1000", "2000.00 (0.00)", "1000.00 (00.00)", "600", 
"700.00 (0.00)", "50.72 (50.00)"), .Dim = 3:2, .Dimnames = list(
    c("n", "unique_n", "Age"), `Stratified by Something` = c("0", 
    "1")))

         Stratified by Something
           0                 1              
  n        "1000"            "600"          
  unique_n "2000.00 (0.00)"  "700.00 (0.00)"
  Age      "1000.00 (00.00)" "50.72 (50.00)"

welshpf avatar Dec 10 '19 21:12 welshpf

Did you use noSpaces = TRUE? Normally the digits are aligned, when using a monospace font (like Courier New) and left aligning the column.

This is just the first example from the help page of CreateTableOne and this can be saved as a csv file without problems.

                         Stratified by trt
                          1                         2                         p      test    SMD   
  n                           158                       154                                        
  time (mean (SD))        2015.62 (1094.12)         1996.86 (1155.93)          0.883          0.017
  status (%)                                                                   0.884 exact    0.054
     0                         83 (52.5)                 85 (55.2)                                 
     1                         10 ( 6.3)                  9 ( 5.8)                                 
     2                         65 (41.1)                 60 (39.0)                                 
  age (mean (SD))           51.42 (11.01)             48.58 (9.96)             0.018          0.270
  sex = f (%)                 137 (86.7)                139 (90.3)             0.421          0.111
  ascites = 1 (%)              14 ( 8.9)                 10 ( 6.5)             0.567          0.089
  hepato = 0/1 (%)          85/73 (53.8/46.2)         67/87 (43.5/56.5)        0.088          0.207
  spiders = 1 (%)              45 (28.5)                 45 (29.2)             0.985          0.016
  edema (%)                                                                    0.877          0.058
     0                        132 (83.5)                131 (85.1)                                 
     0.5                       16 (10.1)                 13 ( 8.4)                                 
     1                         10 ( 6.3)                 10 ( 6.5)                                 
  bili (median [IQR])        1.40 [0.80, 3.20]         1.30 [0.72, 3.60]       0.842 nonnorm  0.171
  chol (median [IQR])      315.50 [247.75, 417.00]   303.50 [254.25, 377.00]   0.544 nonnorm  0.038
  albumin (mean (SD))        3.52 (0.44)               3.52 (0.40)             0.874          0.018
  copper (median [IQR])     73.00 [40.00, 121.00]     73.00 [43.00, 139.00]    0.717 nonnorm <0.001
  alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75]  0.812 nonnorm  0.037
  ast (mean (SD))          120.21 (54.52)            124.97 (58.93)            0.460          0.084
  trig (median [IQR])      106.00 [84.50, 146.00]    113.00 [84.50, 155.00]    0.370 nonnorm  0.017
  platelet (mean (SD))     258.75 (100.32)           265.20 (90.73)            0.555          0.067
  protime (mean (SD))       10.65 (0.85)              10.80 (1.14)             0.197          0.146
  stage (%)                                                                    0.205 exact    0.246
     1                         12 ( 7.6)                  4 ( 2.6)                                 
     2                         35 (22.2)                 32 (20.8)                                 
     3                         56 (35.4)                 64 (41.6)                                 
     4                         55 (34.8)                 54 (35.1)                                 

ndevln avatar Jul 17 '20 09:07 ndevln