How to create an edge list from a matrix in R?

前端 未结 3 1541
粉色の甜心
粉色の甜心 2020-12-09 20:00

The relationship is expressed as a matrix x like this:

      A    B    C     D
A     0    2    1     1
B     2    0    1     0
C     1    1             


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-09 20:48

    using melt in reshape2, and then delete the weight==0. if no need to print the weight. just delete it.

    x
        sample1 sample2 sample3 sample4
    feature1       0       2       1       1
    feature2       2       0       1       0
    feature3       1       1       0       1
    feature4       1       0       1       0
    
    melt(x)
       Var1    Var2 value
    1  feature1 sample1     0
    2  feature2 sample1     2
    3  feature3 sample1     1
    4  feature4 sample1     1
    5  feature1 sample2     2
    

提交回复
热议问题