Deleting specific gtsummary table cell value

I would like to delete the content of the cell corresponding to “Company B”, group “F” and Score_level “low” (it has the value 2 (29%)) for the table generated by the code below.

Searching the gtsummary documentation, there are examples on how to delete a cell value based on its column. In the case of this table, the column name would be stat_1_2.

However, the problem is that this column has two identical values, and i want to keep one of them (cell value for “Company B”, group “F” and Score_level “Average”) and only delete the one mentioned above.

If gt table conversion would help I would gladly use it but have not found a way yet. Any help would be much appreciated.

library(tidyverse)
library(reprex)
library(gtsummary)


Score_level <- c("Low", "High", "Average", "Low", "High", "Average","Low", "High", "Average","Low", "High", "Average","Low", "High", "Average", "Low")
Gender <- c("M", "F", "M", "F","M", "F","M", "F","M", "F","M", "F","M", "F", "M", "F")
Company <- c("Company_A", "Company_B", "Company_B", "Company_A","Company_A", "Company_B","Company_A", "Company_B","Company_A", "Company_B","Company_A", "Company_B","Company_A", "Company_B", "Company_A", "Company_B")

df <- data.frame(Score_level, Gender, Company)


df %>%
  tbl_strata(strata = Company, 
             .tbl_fun = ~ .x %>%
               tbl_summary(by = Gender,
                           statistic = all_categorical() ~ "{n} ({p}%)",
                           missing_text = "(Missing Data)") %>%
               modify_header(label = "**Outcome**")) 

Created on 2023-10-26 with reprex v2.0.2

  • Can you just filter out the value before making the table?

    – 

  • Hi @camille, are you able to share how you would suggest that is done? i was hoping for a gtsummary or gt option, but if that works i would gladly give it a go.

    – 

  • I don’t have gtsummary installed and I’m not sure what output you have right now or exactly what output you want (maybe you can add the output to your reprex). But what I mean is you might want to process your data before getting to the point of making a presentation-ready table. If you’re trying to display summary stats (looks like count & percentage by gender?) you can calculate those beforehand. Or if your processing is filtering, do that beforehand with dplyr, base functions, etc

    – 

  • Hi Camille, I see what you mean, I do not think that would be optimal because this example is a simplified one, from a much larger data set. The aim is to produce dozens of tables and the objective would be to make use of gtsummary’s ability to aggregate the info to present said tables. Thank you for your help nevertheless.

    – 

Leave a Comment