如何使用逗号作为千位分隔符格式化表格1的值

huangapple go评论81阅读模式
英文:

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)

如何使用逗号作为千位分隔符格式化表格1的值

英文:

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 &lt;- melanoma
melanoma2$status &lt;- 
  factor(melanoma2$status, 
         levels=c(2,1,3),
         labels=c(&quot;Alive&quot;, # Reference
                  &quot;Melanoma death&quot;, 
                  &quot;Non-melanoma death&quot;))
table1(~ age + thickness | status, render.continuous=c(.=&quot;Sum&quot;), data=melanoma2)
```

如何使用逗号作为千位分隔符格式化表格1的值

答案1

得分: 0

你可以定义自己的render.continuous函数来格式化值。

library(table1)
library(boot)

table1(~ age + thickness | status, 
       render.continuous = \(x) c(&quot;&quot;, &quot;Sum&quot; = format(sum(x), big.mark = &quot;,&quot;)), 
       data = melanoma2)

如何使用逗号作为千位分隔符格式化表格1的值

英文:

You can define your own render.continuous function to format the values.

library(table1)
library(boot)

table1(~ age + thickness | status, 
       render.continuous = \(x) c(&quot;&quot;, &quot;Sum&quot; = format(sum(x), big.mark = &quot;,&quot;)), 
       data = melanoma2)

如何使用逗号作为千位分隔符格式化表格1的值

huangapple
  • 本文由 发表于 2023年8月9日 13:05:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864728.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定