寻找一些关于用混合类型的列格式化表格的最佳方法的建议,所以有些是整数,其他百分比(显示 %),其他小数点。
有没有一种编辑单个单元格的好方法。尝试过 htmlwidgets 版本的 DT 和 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)