Table 1 median range
I am in love with the package table1 since I discovered it, as it streamlines descriptives to the level of Stata, but in my beloved R! While working on a table today, I have figured out a nice, easy way to incorporate medians and IQRs in the table. Here is the code:
library(table1)Get Lana Bojanić’s stories in your inbox
Join Medium for free to get updates from this writer.
library(flextable)
table1::table1(~ var1 + var2+ var3 + var4 | var5,
data = data, render.missing = NULL,
render.continuous=function (x) {
stats <- c(
median = median(x, na.rm = T),
q1 = quantile(x, 0.25, na.rm = T),
q3 = quantile(x, 0.75, na.rm = T))
sprintf("%.2f (%.0f–%.2f)", stats["median"], stats["q1.25%"], stats["q3.75%"])
},
overall="Total") %>% t1flex()
While figuring it out, I listened to








