網(wǎng)站首頁 編程語言 正文
因為花了2天半才解決,中間痛苦的尋找,記錄一下解決的流程與經(jīng)驗
報錯信息:
1Error in y + 1 : non-numeric argument to binary operator
報錯原因:
數(shù)據(jù)不是可計算的 numeric 或 integer 類型
原代碼:
a = read.table(file = study.txt", sep = "\t",
header = T, row.names = 1
)
class(a[3, 3]) # integer
aa = t(d)
class(aa[3, 3]) # character
b = sparcc(aa)
# 出現(xiàn)報錯
Error in y + 1 : non-numeric argument to binary operator
報錯原因解析:
1. 轉(zhuǎn)置后數(shù)據(jù)類型變?yōu)閏haracter,因為numeric數(shù)據(jù)中存在character類型的臟數(shù)據(jù)
(原因:轉(zhuǎn)置函數(shù)t() 是先將dataframe轉(zhuǎn)換為矩陣matrix,而matrix只有一種數(shù)據(jù)類型。所以如果存在character,所有數(shù)據(jù)都會被轉(zhuǎn)換成character)
如何發(fā)現(xiàn)是否有character臟數(shù)據(jù):
read.table設(shè)置參數(shù)colClasses = “numeric”(確保數(shù)據(jù)框內(nèi)只有numeric類型)
a = read.table(file = study.txt", sep = "\t",
header = T, row.names = 1
colClasses = "numeric" # 添加的參數(shù)
)
# 出現(xiàn)報錯
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
scan() expected 'a real', got 'f__Cenarchaeaceae'
報錯意為 數(shù)據(jù)框內(nèi)存在“f__Cenarchaeaceae”,不屬于numeric
查看txt內(nèi)部
2. 引入character臟數(shù)據(jù)的原因
# 后續(xù)分析需要:設(shè)置data第一列列名為空格
genus <- data[1]
colnames(genus) <- " "
# 根據(jù)列名提取子集
a <- subset(data, select = (disID[, 1]))
subset()函數(shù)將列名為 空格blank 的也提取了,導(dǎo)致了character臟數(shù)據(jù)的進入
總結(jié)
原文鏈接:https://blog.csdn.net/m0_48412773/article/details/125759996
相關(guān)推薦
- 2022-12-25 React安裝node-sass失敗解決方案分享_React
- 2023-05-26 keras.layers.Conv2D()函數(shù)參數(shù)用法及說明_python
- 2022-10-20 Swift協(xié)議Protocol介紹_Swift
- 2022-09-21 Flutter實現(xiàn)底部和頂部導(dǎo)航欄_Android
- 2024-01-12 如何理解 Elasticsearch 中的 Indices、Types、Documents、Fiel
- 2022-11-07 React組件封裝中三大核心屬性詳細介紹_React
- 2022-08-13 深入理解Linux內(nèi)核select多路復(fù)用原理
- 2022-07-08 Nginx將http轉(zhuǎn)換成https的詳細過程_nginx
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支