gpt4 book ai didi

r - 在 kable() 的数字中的每个数字添加逗号

转载 作者:行者123 更新时间:2023-12-05 00:51:41 25 4
gpt4 key购买 nike

我有下面的数据框,我用它创建了一个 kable。如何在每 3 位数字之间添加逗号?

Descs<-structure(list(Mean = c(NaN, 943330388, NaN, NaN, NaN, 543234645, 
45831420, NaN, 27301292, 160818771), Median = c(NaN, 943330388,
NaN, NaN, NaN, 543234645, 45831420, NaN, 27301292, 160818771),
SD = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MAD = c(NA,
0, NA, NA, NA, 0, 0, NA, 0, 0), MIN = c(NA, 943330388, NA,
NA, NA, 543234645, 45831420, NA, 27301292, 160818771), MAX = c(NA,
943330388, NA, NA, NA, 543234645, 45831420, NA, 27301292,
160818771), VAR = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), RANGE = structure(c(NA, 943330388, NA, NA, NA, 543234645,
45831420, NA, 27301292, 160818771, NA, 943330388, NA, NA,
NA, 543234645, 45831420, NA, 27301292, 160818771), .Dim = c(10L,
2L)), QUANTILES = structure(c(NA, 943330388, NA, NA, NA,
543234645, 45831420, NA, 27301292, 160818771, NA, 943330388,
NA, NA, NA, 543234645, 45831420, NA, 27301292, 160818771), .Dim = c(10L,
2L), .Dimnames = list(NULL, c("25%", "75%")))), row.names = c("Comedy",
"Education", "Entertainment", "Film & Animation", "Gaming", "Howto & Style",
"Music", "People & Blogs", "Science & Technology", "Sports"), class = "data.frame")

library(kableExtra)

kable(Descs) %>%
kable_styling(
font_size = 15,
bootstrap_options = c("striped", "hover", "condensed")
)

最佳答案

您可以使用 kable 格式参数,这样可以避免在放入表格之前对数据进行处理。

如果你想清除 NAs 和 NaNs,你可以在这行代码中添加:options(knitr.kable.NA = '')

library(kableExtra)

kable(Descs,
format.args = list(big.mark = ",")) %>%
kable_styling(
font_size = 15,
bootstrap_options = c("striped", "hover", "condensed")
)

enter image description here

关于r - 在 kable() 的数字中的每个数字添加逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71560787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com