【问题标题】:Error saying I have NA/NaN/Inf value when there seems to be none present. Error in hclustfun(distc) : NA/NaN/Inf in foreign function call (arg 11)当似乎不存在时,错误地说我有 NA/NaN/Inf 值。 hclustfun(distc) 中的错误:外部函数调用中的 NA/NaN/Inf (arg 11)
【发布时间】:2019-04-04 12:20:40
【问题描述】:

我有一个看起来像这样的文件:

Taxa,D0,D1,...
1,0,10,...
20,0,0,...
...

文件可在此处获得:https://www.dropbox.com/s/lvtxztz3kypnxre/Taxa_Conf.csv?dl=0

当我运行脚本时

$CONCOCT/scripts/ConfPlot.R -c Taxa_Conf.csv -o Taxa_Conf.pdf

我收到以下错误:

Error in hclustfun(distc) : NA/NaN/Inf in foreign function call (arg 11)
Calls: heatmap.2 -> hclustfun
Execution halted

ConfPlot.R 的样子

#!/usr/bin/Rscript

#load libraries
library(gplots)
library(getopt)

spec = matrix(c('verbose','v',0,"logical",'help','h',0,"logical",'confile','c',1,"character",'ofile','o',1,"character"),byrow=TRUE,ncol=4)

opt=getopt(spec)

if( !is.null(opt$help)) {
cat(getopt(spec, usage=TRUE)); 
q(status=1);
}

confFile <- opt$confile

Conf <- read.csv(confFile,header=TRUE,row.names=1)
Conf.t <- t(Conf)
ConfP <- Conf.t/rowSums(Conf.t)

crp <- colorRampPalette(c("blue","red","orange","yellow"))(100)

pdf(opt$ofile)

heatmap.2 (as.matrix(t(ConfP)),col=crp,trace="none",dendrogram="none",Rowv=FALSE,lwid = c(1.25,4.5),lhei = c(1.25,4.5),cexRow=0.5)

dev.off()

看完Error while creating heatmaps - NA/NaN/Inf in foreign function call (arg 11),我试过了

> a=read.csv("/home/mathed/Simulation/custom_desman/1/Strains/Simulation/Metabat/Taxa_Conf.csv",header=TRUE,row.names=1)
> any(is.na(a))
[1] FALSE

似乎没有 NA 值。 ConfPlot.R 适用于我的其他文件。 问题是什么??似乎没有任何 na、nan 或 inf 值。 提前谢谢你

【问题讨论】:

    标签: r nan na gplots


    【解决方案1】:

    检查这一行:

    ConfP <- Conf.t/rowSums(Conf.t)
    

    它本质上必须是除以零:

    > 0/0
    [1] NaN
    
    > 1/0
    [1] Inf
    

    【讨论】:

    • 哦!我现在明白为什么它会导致 NaN!非常感谢@zx8754
    • 似乎第一列全为零的D0是问题所在!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2014-07-07
    • 2018-07-03
    • 2012-09-05
    相关资源
    最近更新 更多