【R语言报错解决】—存在非数值型变量,Error in c_max * c_min : non-numeric argument to binary operator,如何在数据导入后转为数值型变量?
目錄
- 一、問題回顧
- corrplot及pheatmap均無法繪制熱圖并報錯
- 二、分析原因
- 三、解決方案——將整個矩陣轉(zhuǎn)化為數(shù)值型變量
- 1、友情提示:
- 2、最終方案——apply命令解決
- 3、結(jié)果展示
- 作者介紹
一、問題回顧
corrplot及pheatmap均無法繪制熱圖并報錯
corrplot(test,is.corr=FALSE)
Error in c_max * c_min : non-numeric argument to binary operator
pheatmap(test,cluster_row = FALSE,cluster_col = FALSE)
Error in seq.default(min(x, na.rm = T), max(x, na.rm = T), length.out = n + :
‘from’ must be a finite number
二、分析原因
報錯顯示出現(xiàn)了非數(shù)值型變量
三、解決方案——將整個矩陣轉(zhuǎn)化為數(shù)值型變量
1、友情提示:
不能直接用as.numeric,會把矩陣全部轉(zhuǎn)成一列向量
test<-as.numeric(test)
Warning message:
NAs introduced by coercion
2、最終方案——apply命令解決
test=apply(test,2,as.numeric)#將test矩陣,逐列轉(zhuǎn)為數(shù)值型變量,并再次賦值給testtest=apply(test,2,as.numeric)
Warning message:
In apply(test, 2, as.numeric) : NAs introduced by coercion
3、結(jié)果展示
corrplot(test,is.corr=FALSE)
pheatmap(test,cluster_row = FALSE,cluster_col = FALSE)
作者介紹
何世偉
廈門大學(xué)公共衛(wèi)生碩士
研究方向:表觀遺傳流行病學(xué)、循證醫(yī)學(xué)、生物信息學(xué)
聯(lián)系方式:swheok@foxmail.com
總結(jié)
以上是生活随笔為你收集整理的【R语言报错解决】—存在非数值型变量,Error in c_max * c_min : non-numeric argument to binary operator,如何在数据导入后转为数值型变量?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【主动轮廓模型(二)】《GVF Snak
- 下一篇: 2020软考程序员考试大纲要求的必会单词