0

Looking for some advice on best way to format table with columns of mixed types, so some are integer, other percentages (with % displayed), others decimal points.

Is there a nice way to edit individual cells. Have tried with htmlwidgets version of DT and formattable?

library(data.table)
library(dplyr)

#Data
names <- c("whole-number1","whole-number2","percentage","decimal-1place","decimal-2place")
group1 <- c(101.000,656.000,0.323,0.69,0.88)
group2 <- c(103.000,635.000,0.453,0.67,0.99)
output_table <- data.table(cbind(names,group1,group2))

#html output table
library(formattable)
formattable(output_table,
            list(
              group1=formatter(
                "span",
                style = x ~ ifelse(names == "percentage", 
                                   percent(x,digits=1), NA)))

#html output table
library(DT)
datatable(output_table) %>% 
  formatPercentage("group1",digits=1)
iboboboru
  • 1,112
  • 2
  • 10
  • 21
  • I am not entirely sure what you want to achieve but you might want to have a looks at [tableHTML](https://cran.r-project.org/web/packages/tableHTML/vignettes/tableHTML.html). You can even format individual cells, although you would need some CSS (and it might become tricky if there are too many random (i.e. without a pattern) changes you want to do). Check `replace_html` and the `add_css_` functions. – LyzandeR Mar 14 '17 at 15:57
  • Is html output format a requirement? – Brian D Feb 19 '18 at 22:37

0 Answers0