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