I am trying to build data summary tables in R using the table1 package. Does anyone know if it is possible to specify custom functions to render instead of the stats.default
functions? I want to use the function geoSD and geoMean from the EnvStats package. Any ideas?
Asked
Active
Viewed 606 times
0
1 Answers
2
You can pass in your own custom rendering functions. The function should produce a named character vector where the name of the first element will be replaced by the name of the variable. If you wish to avoid that behavior, make the first element an empty string.
library(table1)
render.continuous.custom <- function(x, ...) {
attr(x, "label") <- NULL # strip labels because geo.+() will choke if present
c(
"",
"geoMean" = format(round(EnvStats::geoMean(x), 3), nsmall = 3),
"geoSD" = format(round(EnvStats::geoSD(x), 3), nsmall = 3)
)
}
table1(~ mpg | factor(cyl), mtcars, render.continuous = render.continuous.custom)

the-mad-statter
- 5,650
- 1
- 10
- 20