如何解决以下问题 "Error in hclust(d, method = hclustfun) : NA/NaN/Inf in foreign function call (arg 11)"

How to fix the following "Error in hclust(d, method = hclustfun) : NA/NaN/Inf in foreign function call (arg 11)"

我正在尝试使用 Spearman correlation/clustering 绘制差异表达实验结果的热图。

代码如下

library(ggplot2)
library(data.table)
library(preprocessCore)
library(limma)
library(dplyr)
install.packages("NMF")
library(NMF)
library(RColorBrewer)
library(tidyverse)

rm(list=ls())

rm(list=ls())
file <- "C:/PETER PROJECT/3d. Mass Spec Processing/Serum Addition Apr 19/Serum     Addition/DE Proteins for heatmap analysis/WCL/.CSV Files/DE Proteins WCL Apr2019 All samples Reanalysis.txt"
data <- read.delim(file, sep="\t", header=T, dec=".")
head(data)   #data <- read.csv("", comment.char="#")
rnames <- data[,1]                            # assign labels in column 1 to    "rnames"
mat_data <- data.matrix(data[,2:ncol(data)])  # transform column 2-5 into a matrix
rownames(mat_data) <- rnames                  # assign row names 
head(mat_data)

dataD.log2 = log2(mat_data)
datat <- t(dataD.log2)

heatmap <- aheatmap(datat, color = "-RdBu:50", scale = "col", breaks = 0,
     annRow = datat["Description"], annColors = "Set2", main = "Comparison of CHO K1 Cells grown in the presence and absence of FBS (Whole Cell Lysates - All Conditions)",
     distfun = "spearman", treeheight=c(50, 50), 
     fontsize=10, cexCol=1, cexRow=1)

数据在一个包含 52000 个元素的矩阵中,所以我不建议 post 它而是有一个新问题,因为我删除了数据中的 NA 和 Zeros。

问题

删除所有 NA 和 Zeros 后,我还应该在我的原始数据中搜索哪些可能导致错误的内容?

您可以使用t函数进行转置。

mat_data <- replace(is.na(t(mat_data)), 0.00)