首页 > 解决方案 > 如何修复以下“hclust(d, method = hclustfun) 中的错误:外部函数调用中的 NA/NaN/Inf (arg 11)”

问题描述

我正在尝试使用 Spearman 相关/聚类来绘制差异表达实验结果的热图。

代码如下

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 个元素的矩阵中,因此我不建议发布它,而是提出一个新问题,因为我删除了数据中的 NA 和 Zero。

问题

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

标签: rcorrelation

解决方案


您可以使用t转置功能。

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

推荐阅读