我正在formattable()
为我的 shinyApp 使用精彩的软件包。这是我遇到的问题的简化示例:
library(formattable)
df <- data.frame(
ID = LETTERS[1:4],
`2018` = c(0.5, 0.9, 0.8, 0.4),
n = c(88, 44, 55, 66),
`2019` = c(0.9, 0.8, 0.7, 0.4),
n = c(78, 84, 54, 25))
names(df)[2] <- '2018'
names(df)[4] <- '2019'
formattable(
df, align = c("l", "r", "l", "r", "l"),
list(
`2018` = function(x) percent(x, digits = 1),
`2019` = function(x) percent(x, digits = 1)
)
)
这很好用,但我希望将列n.1
命名为n
. 当我将列名重命名为n.1
ton
并运行相同的代码来创建表时,最后一列下降...似乎只显示任何具有重复名称的列的第一列。
names(df)[5] <- "n"
formattable(
df, align = c("l", "r", "l", "r", "l"),
list(
`2018` = function(x) percent(x, digits = 1),
`2019` = function(x) percent(x, digits = 1)
)
)
如何n
在列名中同时显示表格?