title: How to combine countpct and binomCI into the same summary statistic to be used in tableby function?
body: <p>I'm using the <code>tableby</code> function from the <code>arsenal</code> package to create summary tables. For most of the statistics I need to generate, this package gives me exactly the format I'm asked except for one. I need to get in the same cell something like this:</p>
  
  <blockquote>
    <p>n (%) [95%CI of the percentage]</p>
  </blockquote>
  
  <p>For now, I'm using the <code>countpct</code> function which gives me the "n (%)" and <code>binomCI</code> which gives me the proportion with 95%CI but it doubles the number of rows in my final table so it's not ideal...</p>
  
  <p>How could I do to have everything on the same line ? </p>
  
  <p>I tried to see if I could create another function from the original ones but I don't really understand their syntax...</p>
  
  <p>Thanks for your help.</p>
  
  <hr>
  
  <p>EDIT : Here is a reproducible example.</p>
  
  <p>Code for the original functions can be found <a href="https://github.com/cran/arsenal/blob/master/R/tableby.stats.R%0A" rel="nofollow noreferrer">here</a>.</p>
  
  <p>So this is what I have now :</p>
  
  <pre><code>data&lt;-NULL
  data$Visit2&lt;-c(rep("Responder",121),rep("Not Responder",29),rep("Responder",4),rep("Not Responder",47))
  data$Group&lt;-c(rep("Tx",150),rep("No Tx",51))
  data&lt;-as.data.frame(data)
  
  
  library(arsenal)
  my_controls &lt;- tableby.control(test = F,total = F,  cat.stats = c("countpct" ,"binomCI"), conf.level = 0.95)
  
  summary(tableby(Group ~ Visit2,
                  data = data, 
                  control = my_controls),
                  digits=2, digits.p=3, digits.pct=1)
  
  # Results :
  |                                |   No Tx (N=51)    |    Tx (N=150)     |
  |:-------------------------------|:-----------------:|:-----------------:|
  |**Visit2**                      |                   |                   |
  |                  Not Responder |    47 (92.2%)     |    29 (19.3%)     |
  |                  Responder     |     4 (7.8%)      |    121 (80.7%)    |
  |                  Not Responder | 0.92 (0.81, 0.98) | 0.19 (0.13, 0.27) |
  |                  Responder     | 0.08 (0.02, 0.19) | 0.81 (0.73, 0.87) |
  
  
  
  
  
  
  
  And this is what I want :
  
  |                 |        No Tx (N=51)       |        Tx (N=150)        |
  |:----------------|:-------------------------:|:------------------------:|
  |**Visit2**                                   |                          |                 
  |   Not Responder |  47 (92.2%) [81.1, 97.8]  |  29 (19.3%) [13.3, 26.6] |   
  |   Responder     |   4 (7.8%) [2.2, 18.9]    | 121 (80.7%) [73.4, 86.7] |
  |                  
  
  </code></pre>