【发布时间】:2015-08-01 22:47:47
【问题描述】:
我无法弄清楚如何使用 is.na(x) 之类的函数来处理 R 中的无限数和数据表,或者显示每列有多少 Inf:colSums(is.infinite(x))
我使用以下示例数据集:
DT <- data.table(a=c(1/0,1,2/0),b=c("a","b","c"),c=c(1/0,5,NA))
DT
a b c
1: Inf a Inf
2: 1 b 5
3: Inf c NA
colSums(is.na(DT))
a b c
0 0 1
colSums(is.infinite(DT))
Error in is.infinite(DT) : default method not implemented for type 'list'
DT[is.na(DT)] <- 100
DT
a b c
1: Inf a Inf
2: 1 b 5
3: Inf c 100
DT[is.infinite(DT)] <- 100
Error in is.infinite(DT) : default method not implemented for type 'list'
我在this post 中找到了如何用 NA 替换 Inf,但我想说应该有更好的方法来实现这一点,例如 is.infinite。我想看看 Inf 的每列,对此有什么想法吗?
非常感谢。 BR蒂姆
【问题讨论】:
标签: r data.table infinite na