Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can tbl_summary() leave empty value instead of NA/ missing values?

I am using tbl_summary() to summarize clinical characteristics of a patient cohort.

I have a patient group and a control group. My problem is that I have more variables for the patient group (blood counts etc.) that are not available for the control group.

Example data:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

library(gtsummary)

group <- rep(c("Kontrol","Patient"),times=c(5,10))
age <- floor(runif(15, min=20, max=101))
sex <- rep(c("male","female","male","female"), times=c(3,2,7,3))
Hemoglobin <-  as.numeric(c(rep("",times=5),7.21,7.52,10.41,10.03,8.95,6.24,8.54,14.22,8.76,7.57))

df <- data.frame(group,age,sex,Hemoglobin)

df %>% tbl_summary(by=group)

enter image description here

so my question is can I make a table where these variables will have an empty value in the control column? something like:
enter image description here

Thanks for your help!

>Solution :

It seems that you can’t achieve the desired results only by using the arguments provided by the function (e.g. missing and missing_text arguments). You have to locally modify the list object.

library(gtsummary)

group <- rep(c("Kontrol","Patient"),times=c(5,10))
age <- floor(runif(15, min=20, max=101))
sex <- rep(c("male","female","male","female"), times=c(3,2,7,3))
Hemoglobin <-  as.numeric(c(rep("",times=5),7.21,7.52,10.41,10.03,8.95,6.24,8.54,14.22,8.76,7.57))

df <- data.frame(group,age,sex,Hemoglobin)

table <- 
  df %>% 
  tbl_summary(by=group, missing="no")  

table$table_body$stat_1[table$table_body$stat_1 == "NA (NA, NA)"] <- NA

table

Created on 2022-01-14 by the reprex package (v2.0.1)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading