Я пытаюсь использовать 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))
))
)
![enter image description here](https://i.stack.imgur.com/k1I1b.png)