首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >dist中的警告(mat,method = Error ):NAs由hclust中的强制错误引入(d,方法=方法):外函数调用中的NA/NaN/Inf (arg 10)

dist中的警告(mat,method = Error ):NAs由hclust中的强制错误引入(d,方法=方法):外函数调用中的NA/NaN/Inf (arg 10)
EN

Stack Overflow用户
提问于 2022-05-17 13:29:17
回答 1查看 421关注 0票数 0

我正在尝试使用pheatmap()函数生成一个heatmap。但是,我看到一个错误,在dataframe中存在NA/NaN/Inf。我检查它,但是里面没有NA/NaN/Inf值。这个函数以前起过作用,所以我不知道我做错了什么.有什么建议吗?

代码语言:javascript
运行
复制
heat<-pheatmap(mat, kmeans_k = NA, breaks = NA, border_color= "grey60",cellwidth = 5, cellheight = 0.05, scale = "none", cluster_rows = TRUE,
         cluster_cols = TRUE, clustering_distance_rows = "euclidean",
         clustering_distance_cols = "euclidean", clustering_method = "complete",
         cutree_rows = 1, cutree_cols = 1,
         legend_labels = NA, annotation_row = NA, annotation_col = pd,
         annotation = pd, annotation_colors = anno_colors, annotation_legend = TRUE,
         annotation_names_row = TRUE, annotation_names_col = TRUE,
         drop_levels = TRUE, show_rownames = F, show_colnames = T, main = NA, fontsize = 4,
         fontsize_row = 4, fontsize_col = 4,
         display_numbers = F, number_format = "%.2f", number_color = "grey30",
         fontsize_number = 0.8 * fontsize, gaps_row = NULL, gaps_col = NULL,
         labels_row = NULL, labels_col = NULL, filename = NA, width = NA,
         height = NA, silent = FALSE)
代码语言:javascript
运行
复制
Warning in dist(mat, method = distance) : NAs introduced by coercion
Error in hclust(d, method = method) : 
  NA/NaN/Inf in foreign function call (arg 10)
EN

回答 1

Stack Overflow用户

发布于 2022-05-17 15:07:47

这些错误和警告的可能原因之一是矩阵mat中存在一个非数字向量。

例如,iris数据帧中的前四列是数字向量,第五列是字符向量。如果将所有列作为pheatmap的输入,则会弹出错误和警告消息:

代码语言:javascript
运行
复制
pheatmap(as.matrix(iris)) # failed.

#Error in hclust(d, method = method) : 
#  NA/NaN/Inf in foreign function call (arg 10)
#In addition: Warning messages:
#1: In dist(mat, method = distance) : NAs introduced by coercion
#2: In dist(mat, method = distance) : NAs introduced by coercion

如果只包含数字列,则执行该函数时不存在错误或警告。

代码语言:javascript
运行
复制
pheatmap(as.matrix(iris[,1:4]))  # succeeded.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72274937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档