假设我有一个如下所示的数组:
d = matrix(rnorm(25,0,10), nrow = 5) %>% round(2)
这给了我:
structure(c(-7.53, 23.22, -4.42, -5.38, 10.84, -36.38, -10.87,
-7.44, -9.18, 0.71, 25.82, 16.18, -9.25, -7.04, 10.13, -11.55,
-7.54, -4.74, -12.67, 20.46, -11.26, 6.57, -1.46, 4.54, -4.93
), dim = c(5L, 5L))
我想以某种方式更容易地发现绝对值大于 10 的单元格,可以通过突出显示它们(可以在
xtable()
打印中),或者删除/更改为 0 个其他值。我该怎么做?
我的实际对象是
.stdres
的 chisq.test()
输出(我无法共享数据),如果有一种方法可以直接在函数中突出显示它也有帮助。
如果您在 R Studio 中并且需要目视检查方面的帮助,您可以使用
reactable
、kableExtra
、flextable
或类似工具。
这是带有
reactable
的一个:
reactable::reactable(
aux,
defaultColDef = colDef(
style = function(value) {
color <- case_when(
value > 10 ~ "lightblue",
value < -10 ~ "lightpink",
TRUE ~ "white")
list(backgroundColor = color)}))
# Toy data
aux <- structure(
c(-7.53, 23.22, -4.42, -5.38, 10.84, -36.38, -10.87, -7.44, -9.18,
0.71, 25.82, 16.18, -9.25, -7.04, 10.13, -11.55, -7.54, -4.74,
-12.67, 20.46, -11.26, 6.57, -1.46, 4.54, -4.93),
dim = c(5L, 5L))
输出是查看器窗格中的 html 表格: