在数据表 (R) 中每三位数字添加逗号 [英] Add comma to numbers every three digits in datatable (R)

查看:24
本文介绍了在数据表 (R) 中每三位数字添加逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的数据如下所示:

df1 = data.frame(A=c(1000000.51,5000.33), B=c(0.565,0.794))

我想使用

Suppose my data looks like this:

df1 = data.frame(A=c(1000000.51,5000.33), B=c(0.565,0.794))

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)

I know i can use scales

library(scales)    
comma_format()(1000000)

but I'm not sure how to combine that with DataTables

Thanks!

解决方案

Had this same issue:

Try This:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆