我的矩阵像这样-
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将不假定行名,而是添加编号。但是我需要行名和列名而不是数字。
答案 0 :(得分:0)
只需将名称定义为第一列...
Pmatrix<- read.csv(text = ",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")
sig_values <- which(Pmatrix==1, arr.in=TRUE)
cbind.data.frame(colIDs = colnames(Pmatrix)[ sig_values[, 2] ],rowIDs = Pmatrix[,1][ sig_values[, 1] ])
#> colIDs rowIDs
#> 1 NBAS NBAS
#> 2 DNAH9 DNAH9
#> 3 NRAS NRAS
#> 4 NRAS.1 NRAS
#> 5 TP53 TP53
#> 6 TP53.1 TP53
#> 7 TP53.2 TP53
#> 8 SCYL2 SCYL2
#> 9 RNF19A RNF19A