1

I'm using the table1 package to create summary statistics. My current table1() looks like this (code below):

current table1()

I want to add another section, with a labeled row in bold called "Co-occurring disorder", that is not referring to a specific variable. I want two un-bolded rows after it refers to just the number of TRUE in two distinct variables: "Mental Health" for one row and "Substance use" for another. For example, if 12 people have TRUE for "mental health" and 7 people have TRUE for "substance use," the following row would start like this:

example next row

Alternatively, how do I add a blank row to the table?

My current code is pasted below.

    library(table1)
    opp2$SEX <- 
      factor(opp2$SEX, levels=c(1,2),
             labels=c("Male", "Female"))
    opp2$REGION <-
      factor(opp2$REGION, levels=c(1:5),
             labels = c("Northeast", "North Central", "South", "West", "Unknown"))
    opp2$GS <- factor(opp2$GS, levels = c(1:5),
                      labels = c("Male", "Female", 
                                 "Transmasculine", "Transfeminine", "Unknown"))
    
    #units(opp2$AGE)       <- "years"
    
    
    labels <- list(variables=list(SEX="Sex",
                                  AGE="Age (years)",
                                  REGION="Region"),
                   groups=list("", "Cis", "TGM"))
    strata <- c(list(Total=opp2), split(opp2, opp2$GS))
    
    
    my.render.cont <- function(x) {
      with(stats.apply.rounding(stats.default(x), digits=2), 
           c("",
             "Median (IQR)"=sprintf("%s (&plusmn; %s)", MEDIAN, IQR)))
    }
    my.render.cat <- function(x) {
      c("", sapply(stats.default(x), 
                   function(y) with(y, sprintf("%d (%0.0f %%)", FREQ, PCT))))
    }
    
    table1(strata, labels, groupspan=c(1,2, 3),
           render.continuous=my.render.cont, render.categorical=my.render.cat)`
Andrea M
  • 2,314
  • 1
  • 9
  • 27
amburguesa
  • 11
  • 2
  • I think this goes against the `table1` logic - usually non-bold labels indicate levels of a same variable, so a reader might be tricked into thinking that mental healths disorders and substance use are mutually exclusive – Andrea M Aug 05 '22 at 08:31
  • The solution is here: https://github.com/benjaminrich/table1/issues/98 – mrbrich Mar 18 '23 at 18:16

0 Answers0