Add comma to numbers every three digits in datatable (R)
I'm not sure if formatRound()
was created after this question was asked and answered, but here's a solution without using formatCurrency()
(which seems a little hackish):
library(DT)
library(dplyr)
df1 = data.frame(A=c(1000000.51,5000.33, 2500, 251), B=c(0.565,0.794, .685, .456))
datatable(df1) %>%
formatPercentage('B', digits = 2) %>%
formatRound('A', digits = 0)
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 = ",")
You could use formatC
library(dplyr)
library(DT)
df1 %>%
mutate(A = formatC(round(A), format = "f", big.mark = ",", drop0trailing = TRUE),
B = paste0(formatC(100 * B, format = "f", digits = 2), "%")) %>%
datatable()
Which gives: