【发布时间】:2019-09-12 21:21:40
【问题描述】:
我的矩阵是这样的-
13367*13367长矩阵-
NBAS DNAH9 NRAS NRAS TP53 TP53 TP53 SCYL2 RNF19A
NBAS 1 0 0 0 0 0 0 0 0
DNAH9 0 1 0 0 0 0 0 0 0
NRAS 0 0 1 0 0 0 0 0 0
NRAS 0 0 0 1 0 0 0 0 0
TP53 0 0 0 0 1 0 0 0 0
TP53 0 0 0 0 0 1 0 0 0
TP53 0 0 0 0 0 0 1 0 0
SCYL2 0 0 0 0 0 0 0 1 0
RNF19A 0 0 0 0 0 0 0 0 1
我需要提取值等于 1 的所有行和列标题对。我正在使用以下 R 脚本-
Pmatrix = read.csv ("file.csv", header= TRUE, row.names = 1)
sig_values <- which(Pmatrix==1, arr.in=TRUE)
cbind.data.frame(colIDs = colnames(Pmatrix)[ sig_values[, 1] ],rowIDs = rownames(Pmatrix)[ sig_values[, 2] ])
但出现错误-
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
duplicate 'row.names' are not allowed
如果我输入row.names = False,R 将假定没有行名并添加编号。但我需要的是行名和列名而不是数字。
【问题讨论】:
-
你试过
fread从data.table吗? -
不,如何在哪里使用那个函数?
-
怎么会有同名的列和行?