寻找关于使用混合类型列格式化表格的最佳方法的一些建议,因此有些是整数,其他百分比(显示%),其他小数点。
是否有一种编辑单个细胞的好方法。尝试过使用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)