r - 在 R 中使用 formattable 组合列
问题描述
我正在尝试使用 formattable on 来更好地可视化表格。我想要做的是将列名称和差异组合在一起显示在一列下。我已经格式化了列差异。我如何在这里组合以将它们显示为一列:
library(readr)
library(formattable)
df <- data.frame(
id = 1:10,
name = c("Bob", "Ashley", "James", "David", "Jenny",
"Hans", "Leo", "John", "Emily", "Lee"),
test1_score = c(8.9, 9.5, 9.6, 8.9, 9.1, 9.3, 9.3, 9.9, 8.5, 8.6),
test2_score = c(9.1, 9.1, 9.2, 9.1, 8.9, 8.5, 9.2, 9.3, 9.1, 8.8),
stringsAsFactors = FALSE)
formattable(
df %>%
mutate("difference" = df$test1_score - df$test2_score),
list(difference = formatter(
"span",
style = x ~ style(color = ifelse(x >= 0, "green", "red")),
x ~ icontext(ifelse(x >= 0, "arrow-up", "arrow-down"), round(x, 2))
))
)
解决方案
推荐阅读
- javascript - 如何在 Laravel 中调试 javascript(从浏览器控制台)?
- angularjs - 更改图表类型后,刻度线正在移动
- javascript - 无法在controllerFunction节点js中获取url参数
- android - android VideoView 无法播放此视频错误
- tensorflow - 最后的神经网络
- c# - 从资源中声明一个 const 字符串
- asp.net-core - 如何在 OpenIdConnect TokenValidated 偶数处理程序中访问 Session
- angular - 运行时错误:this.userprovider.userSignup(...).subscribe 不是 Ionic 中的函数
- spring-mvc - 如何在 Spring MVC 的 Rest Controller 中将 Bean 类对象作为 JSON 返回
- networking - P2P 网络引导