【问题标题】:Transform matrix to a list of pairs将矩阵转换为对列表
【发布时间】:2014-03-19 12:21:29
【问题描述】:

我有这个互信息矩阵:

X1053_at X117_at X121_at X1255_g_at X1294_at X1316_at X1320_at X1053_at 0 0.00040833 0.052000448 0.101470422 0.00040833 0.223143551 X117_at 0.00040833 0 0.00040833 0.174561677 0.174561677 0.034204976 X121_at 0.052000448 0.00040833 0 0.020410997 0.010309644 0.034204976 X1255_g_at 0.101470422 0.174561677 0.020410997 0 0.020410997 0.174561677 X1294_at 0.00040833 0.174561677 0.010309644 0.020410997 0 0.101470422 X1316_at 0.223143551 0.034204976 0.034204976 0.174561677 0.101470422 0 X1320_at 0.074226329 0.134540323 0.052000448 0.00368703 0.020410997 0.101470422

然后我想在 R 中制作一个基因列表制表符分隔矩阵,例如:

基因X基因Y重量 基因X基因Y重量 基因X基因Y重量 基因X基因Y重量 基因X基因Y重量 基因X基因Y重量

谁能帮我解决这个问题? 实际上我想导出这个矩阵,然后通过 cytoscape 或 gephi 导入或...... 谢谢

【问题讨论】:

    标签: r matrix adjacency-matrix


    【解决方案1】:

    以下 hack 可能会有所帮助:

    x <- as.matrix(read.table(textConnection("X1053_at   X117_at X121_at X1255_g_at  X1294_at    X1316_at    X1320_at
    X1053_at    0   0.00040833  0.052000448 0.101470422 0.00040833  0.223143551
    X117_at     0.00040833  0   0.00040833  0.174561677 0.174561677 0.034204976
    X121_at     0.052000448 0.00040833  0   0.020410997 0.010309644 0.034204976
    X1255_g_at  0.101470422 0.174561677 0.020410997 0   0.020410997 0.174561677
    X1294_at    0.00040833  0.174561677 0.010309644 0.020410997 0   0.101470422
    X1316_at    0.223143551 0.034204976 0.034204976 0.174561677 0.101470422 0
    X1320_at    0.074226329 0.134540323 0.052000448 0.00368703  0.020410997 0.101470422"), header=TRUE, row.names=1))
    
    # not sure if this is correctly aligned as you have 7 column names for 6 columns
    
    as.data.frame(as.table(x))
    

    结果:

             Var1       Var2       Freq
    1    X1053_at    X117_at 0.00000000
    2     X117_at    X117_at 0.00040833
    3     X121_at    X117_at 0.05200045
    4  X1255_g_at    X117_at 0.10147042
    5    X1294_at    X117_at 0.00040833
    

    【讨论】:

    • @ lebatsnok 谢谢你,完美,我做了一点改动,它对归档矩阵起作用,如下所示:x = as.matrix(MIM 矩阵文件名) as.data.frame (as.table(x))
    猜你喜欢
    • 2011-01-29
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 2014-05-07
    相关资源
    最近更新 更多