在数据表(R)中每三位数加一个逗号 [英] Add comma to numbers every three digits in datatable (R)
本文介绍了在数据表(R)中每三位数加一个逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的数据如下:
df1 = data.frame(A=c(1000000.51,5000.33), B=c(0.565,0.794))
我想使用 DataTables 并将A列设为(1,000,001; 5,000)
I want to use DataTables and have column A be (1,000,001 ; 5,000)
library(DT)
datatable(df1) %>% formatPercentage('B', 2) %>%
formatRound('A',digits = 0)
我知道我可以使用磅秤
library(scales)
comma_format()(1000000)
但我不确定如何将其与DataTables结合使用
but I'm not sure how to combine that with DataTables
谢谢!
推荐答案
有同样的问题:
尝试一下:
require(DT)
require(dplyr)
df1 = data.frame(A=c(1000000.51,5000.33, 2500, 251), B=c(0.565,0.794, .685, .456))
df1 <- df1 %>% mutate(A=round(A,digits=0))
datatable(df1) %>% formatPercentage('B', 2) %>%
formatCurrency('A',currency = "", interval = 3, mark = ",")
这篇关于在数据表(R)中每三位数加一个逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文