gpt4 book ai didi

r - 在 DT::datatable() 中显示 Inf

转载 作者:行者123 更新时间:2023-12-04 12:06:51 25 4
gpt4 key购买 nike

我想明确显示 Inf数据表中的值而不是空白

iris[1, 1] <- Inf
DT::datatable(iris[1:2, ])
enter image description here
我不想打开列信息字符来对列进行排序(如果我这样做,排序将按字母顺序排列)
有任何想法吗?

编辑:
我认为可以调整这种代码:
datatable(iris[c(1:20), ], options = list(columnDefs = list(list(
targets = 5,
render = JS(
"function(data, type, row, meta) {",
"return type === 'display' && data.length > 2 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 2) + '...</span>' : data;",
"}")
))))
使用@MLavoie 解决方案,它没有区别 NAInf
df = iris
df[1,1]<-Inf
df[2,1]<-NA
DT::datatable(df)
library(DT)
DT::datatable(df[,], options = list(columnDefs = list(list(
targets = 1,
render = JS(
"function(data, type, row, meta) {",
"return data === null ? 'Inf' : data;",
"}")
))))

最佳答案

解决办法是:

options(htmlwidgets.TOJSON_ARGS = list(na = 'string'))

iris[1,1] <- NA
iris[2,1] <- Inf
DT::datatable(head(iris))

感谢@yihui-xie 和@Jeroen: https://github.com/rstudio/DT/issues/496#issuecomment-363867449

关于r - 在 DT::datatable() 中显示 Inf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48592842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com