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

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

How to format table1 values with comma as the thousands separator

问题

我想知道是否有人可以帮助我格式化一个表格1。我需要用逗号格式化我的“Sum”连续值。以下是代码和截图:提前感谢。

  1. library(boot)
  2. library(table1)
  3. melanoma2 <- melanoma
  4. melanoma2$status <-
  5. factor(melanoma2$status,
  6. levels=c(2,1,3),
  7. labels=c("Alive", # Reference
  8. "Melanoma death",
  9. "Non-melanoma death"))
  10. 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.

  1. ```{r}
  2. library(boot)
  3. library(table1)
  4. melanoma2 &lt;- melanoma
  5. melanoma2$status &lt;-
  6. factor(melanoma2$status,
  7. levels=c(2,1,3),
  8. labels=c(&quot;Alive&quot;, # Reference
  9. &quot;Melanoma death&quot;,
  10. &quot;Non-melanoma death&quot;))
  11. table1(~ age + thickness | status, render.continuous=c(.=&quot;Sum&quot;), data=melanoma2)
  12. ```

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

答案1

得分: 0

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

  1. library(table1)
  2. library(boot)
  3. table1(~ age + thickness | status,
  4. render.continuous = \(x) c(&quot;&quot;, &quot;Sum&quot; = format(sum(x), big.mark = &quot;,&quot;)),
  5. data = melanoma2)

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

英文:

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

  1. library(table1)
  2. library(boot)
  3. table1(~ age + thickness | status,
  4. render.continuous = \(x) c(&quot;&quot;, &quot;Sum&quot; = format(sum(x), big.mark = &quot;,&quot;)),
  5. 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:

确定