0

my matrix is like this- 13367*13367 long matrix-

    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

I need to extract all pairs of rows and column headers for which the value is equal to 1 . I m using the following R script-

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] ])

but getting error-

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  duplicate 'row.names' are not allowed

If I will put row.names = False R will assume no rownames and add numbering instead. But i need the row names and column names not the numbers.

xrxrxrxxr
  • 89
  • 1
  • 7

1 Answers1

0

Just define the names as the first column...

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
shosaco
  • 5,915
  • 1
  • 30
  • 48