英文:
How to format table1 values with comma as the thousands separator
问题
我想知道是否有人可以帮助我格式化一个表格1。我需要用逗号格式化我的“Sum”连续值。以下是代码和截图:提前感谢。
library(boot)
library(table1)
melanoma2 <- melanoma
melanoma2$status <-
factor(melanoma2$status,
levels=c(2,1,3),
labels=c("Alive", # Reference
"Melanoma death",
"Non-melanoma death"))
table1(~ age + thickness | status, render.continuous=c(.="Sum"), data=melanoma2)
英文:
I wonder if someone can help me to format a table1. I need to format my "Sum" continuous values with commas. Code and screenshot below: Thanks beforehand.
```{r}
library(boot)
library(table1)
melanoma2 <- melanoma
melanoma2$status <-
factor(melanoma2$status,
levels=c(2,1,3),
labels=c("Alive", # Reference
"Melanoma death",
"Non-melanoma death"))
table1(~ age + thickness | status, render.continuous=c(.="Sum"), data=melanoma2)
```
答案1
得分: 0
你可以定义自己的render.continuous
函数来格式化值。
library(table1)
library(boot)
table1(~ age + thickness | status,
render.continuous = \(x) c("", "Sum" = format(sum(x), big.mark = ",")),
data = melanoma2)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论