我正在尝试使用table1包在R中构建数据汇总表。有没有人知道是否可以指定自定义函数来呈现,而不是stats.default函数?我想使用EnvStats包中的函数geoSD和geoMean。有什么想法吗?
发布于 2021-02-04 10:38:05
您可以传入您自己的自定义渲染函数。该函数应该生成一个命名的字符向量,其中第一个元素的名称将被变量的名称替换。如果您希望避免这种行为,请将第一个元素设置为空字符串。
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)

https://stackoverflow.com/questions/65854293
复制相似问题