formatCurrency {DT} | R Documentation |
Format numeric columns in a table as currency (formatCurrency()
) or
percentages (formatPercentage()
), or round numbers to a specified
number of decimal places (formatRound()
). The function
formatStyle()
applies CSS styles to table cells by column.
formatCurrency(table, columns, currency = "$", interval = 3, mark = ",") formatPercentage(table, columns, digits = 0) formatRound(table, columns, digits = 2) formatDate(table, columns, method = "toDateString") formatStyle(table, columns, fontWeight = NULL, color = NULL, backgroundColor = NULL, background = NULL, ...)
table |
a table object created from |
columns |
the indices of the columns to be formatted (can be character,
numeric, logical, or a formula of the form |
currency |
the currency symbol |
interval |
put a marker after how many digits of the numbers |
mark |
the marker after every |
digits |
the number of decimal places to round to |
method |
the method(s) to convert a date to string in JavaScript; see
|
fontWeight |
the font weight, e.g. |
color |
the font color, e.g. |
backgroundColor |
the background color of table cells |
background |
the background of table cells |
... |
other CSS properties, e.g. |
See http://rstudio.github.io/DT/functions.html for detailed documentation and examples.
library(DT) m = cbind(matrix(rnorm(120, 1e5, 1e6), 40), runif(40), rnorm(40, 100)) colnames(m) = head(LETTERS, ncol(m)) m # format the columns A and C as currency, and D as percentages datatable(m) %>% formatCurrency(c('A', 'C')) %>% formatPercentage('D', 2) # the first two columns are Euro currency, and round column E to 3 decimal places datatable(m) %>% formatCurrency(1:2, '\U20AC') %>% formatRound('E', 3) # apply CSS styles to columns datatable(iris) %>% formatStyle('Sepal.Length', fontWeight = styleInterval(5, c('bold', 'weight'))) %>% formatStyle('Sepal.Width', color = styleInterval(3.4, c('red', 'white')), backgroundColor = styleInterval(3.4, c('yellow', 'gray')) )