'How to combine countpct and binomCI into the same summary statistic to be used in tableby function?

I'm using the tableby function from the arsenal 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:

n (%) [95%CI of the percentage]

For now, I'm using the countpct function which gives me the "n (%)" and binomCI which gives me the proportion with 95%CI but it doubles the number of rows in my final table so it's not ideal...

How could I do to have everything on the same line ?

I tried to see if I could create another function from the original ones but I don't really understand their syntax...

Thanks for your help.


EDIT : Here is a reproducible example.

Code for the original functions can be found here.

So this is what I have now :

data<-NULL
data$Visit2<-c(rep("Responder",121),rep("Not Responder",29),rep("Responder",4),rep("Not Responder",47))
data$Group<-c(rep("Tx",150),rep("No Tx",51))
data<-as.data.frame(data)


library(arsenal)
my_controls <- 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] |
|                  



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source