For continuous variables in my dataframe, I want to use the table1 package in R to get a table showing median (25th-75th percentile) as output for each continuous variable.
Using the method described by Benjamin Rich in a table1 vignette:
my.render.cont <- function(x) {
with(stats.apply.rounding(stats.default(x), digits=2), c("",
"Mean (SD)"=sprintf("%s (± %s)", MEAN, SD)))
}
How do I change this to instead of showing the data like Median (+/- IQR) to show it like Median (25th percentile - 75th percentile)?
If a reproducible example is needed:
library(table1)
library(MASS)
labels <- list(variables=list(age="Age (years)",thickness="Thickness (mm)"),groups=list("", "", ""))
strata <- split(Melanoma, Melanoma$status)
my.render.cont <- function(x) {
with(stats.apply.rounding(stats.default(x), digits=2), c("",
"Mean (SD)"=sprintf("%s (± %s)", MEAN, SD)))
}
table1(strata, labels, render.continuous=my.render.cont)
Try this:
library(table1)
library(MASS)
labels <- list(variables=list(age="Age (years)",thickness="Thickness (mm)"),groups=list("", "", ""))
strata <- split(Melanoma, Melanoma$status)
my.render.cont <- function(x) {
with(stats.apply.rounding(stats.default(x, ), digits = 2),
c("",
"median (Q1-Q3)" =
sprintf(paste("%s (",Q1,"- %s)"), MEDIAN,Q3)))
}
table1(strata, labels, render.continuous=my.render.cont)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.