使用melt命令匹配数据集中的列

时间:2019-06-13 20:12:35

标签: r reshape melt

我有data.frame,其中包含DNA和RNA样品的频率信息。我有7个与DNA相关的列和5个与RNA相关的列。

Genome  Position    Information DNA.1   DNA.2   DNA.3   DNA.4   DNA.5   DNA.6   DNA.7   RNA.1   RNA.2   RNA.3   RNA.4   RNA.5
A   73016   Deletion    0.577049    0.690323    0.64759 0.691057    0.805687    0.1 0.1 NA  NA  NA  1   1
A   1586741 Deletion    0   0   0   0   0.285393    0.1 0.1 NA  NA  0.538462    0.5 0.733333
A   3836856 Deletion    0.020161    0.018779    0.012987    0.019011    0.070845    0.1 0.1 NA  NA  NA  0.28125 NA
A   624896  Deletion    0.086247    0.103158    0.056738    0.033755    0.297767    0.1 0.1 NA  NA  NA  0.87234 NA
A   3864884 Deletion    0   0   0   0   0.617521    0.1 0.1 0.727273    0.275862    0.5 0.416667    0.121951
A   253079  Deletion    0   0   0   0   0.134703    0.1 0.1 NA  NA  0.615385    0.40625 1
A   252823  Insertion   0   0   0   0   0.121145    0.1 0.1 NA  NA  0.333333    0.375   0.727273
A   71504   Insertion   0   0.359848    0   0   0.102689    0.1 0.1 NA  NA  NA  0.4 NA
A   62414   Insertion   0   0   0   0   0.32133 0.1 0.1 NA  NA  0.545455    0.15    0.863636
A   255436  Insertion   0   0.032864    0   0   0.169811    0.1 0.1 NA  NA  0.727273    0.56    1
A   625925  Insertion   0   0.097619    0   0   0.244565    0.1 0.1 NA  0.846154    0.769231    0.854167    1
A   623946  Insertion   0   0   0   0   0.203704    0.1 0.1 NA  0.733333    0.846154    0.333333    NA
A   623491  Insertion   0   0   0   0   0.158358    0.1 0.1 NA  NA  0.9 0.807692    NA
A   630788  None    0   0   0   0   0   0.1 0.1 NA  NA  NA  NA  0.714286
A   2215661 None    0.039841    0.043956    0.078788    0   0.0625  0.1 0.1 NA  NA  0.277778    0.21875 0.230769

DNA.1和RNA.1列是从同一样品中获得的结果,DNA.2和RNA.2是从同一样品中获得的结果,依此类推...您可以看到没有相应的RNA.6和DNA.6和DNA.7数据的RNA.7数据列。我想生成两个新列,其中一列显示所有DNA,另一列显示所有RNA数据(每一行具有匹配的DNA和RNA数据)。我想转换为这种格式或任何其他建议您可以绘制DNA与RNA点图的图表。但是,由于我有两个额外的列,我有点困惑如何安排数据集。

    Genome  Position    Information DNA RNA
A   73016   Deletion    0.577049    NA
A   1586741 Deletion    0   NA
A   3836856 Deletion    0.020161    NA
A   624896  Deletion    0.086247    NA
A   3864884 Deletion    0   0.727273
A   253079  Deletion    0   NA
A   252823  Insertion   0   NA
A   71504   Insertion   0   NA
A   62414   Insertion   0   NA
A   255436  Insertion   0   NA
A   625925  Insertion   0   NA
A   623946  Insertion   0   NA
A   623491  Insertion   0   NA
A   630788  None    0   NA
A   2215661 None    0.039841    NA
A   73016   Deletion    0.690323    NA
A   1586741 Deletion    0   NA
A   3836856 Deletion    0.018779    NA
A   624896  Deletion    0.103158    NA
A   3864884 Deletion    0   0.275862
A   253079  Deletion    0   NA
A   252823  Insertion   0   NA
A   71504   Insertion   0.359848    NA
A   62414   Insertion   0   NA
A   255436  Insertion   0.032864    NA
A   625925  Insertion   0.097619    0.846154
A   623946  Insertion   0   0.733333
A   623491  Insertion   0   NA
A   630788  None    0   NA
A   2215661 None    0.043956    NA
A   73016   Deletion    0.64759 NA
A   1586741 Deletion    0   0.538462
A   3836856 Deletion    0.012987    NA
A   624896  Deletion    0.056738    NA
A   3864884 Deletion    0   0.5
A   253079  Deletion    0   0.615385
A   252823  Insertion   0   0.333333
A   71504   Insertion   0   .
A   62414   Insertion   0   0.545455
A   255436  Insertion   0   0.727273
A   625925  Insertion   0   0.769231
A   623946  Insertion   0   0.846154
A   623491  Insertion   0   0.9
A   630788  None    0   NA
A   2215661 None    0.078788    0.277778
A   73016   Deletion    0.691057    1
A   1586741 Deletion    0   0.5
A   3836856 Deletion    0.019011    0.28125
A   624896  Deletion    0.033755    0.87234
A   3864884 Deletion    0   0.416667
A   253079  Deletion    0   0.40625
A   252823  Insertion   0   0.375
A   71504   Insertion   0   0.4
A   62414   Insertion   0   0.15
A   255436  Insertion   0   0.56
A   625925  Insertion   0   0.854167
A   623946  Insertion   0   0.333333
A   623491  Insertion   0   0.807692
A   630788  None    0   NA
A   2215661 None    0   0.21875
A   73016   Deletion    0.805687    1
A   1586741 Deletion    0.285393    0.733333
A   3836856 Deletion    0.070845    NA
A   624896  Deletion    0.297767    NA
A   3864884 Deletion    0.617521    0.121951
A   253079  Deletion    0.134703    1
A   252823  Insertion   0.121145    0.727273
A   71504   Insertion   0.102689    NA
A   62414   Insertion   0.32133 0.863636
A   255436  Insertion   0.169811    1
A   625925  Insertion   0.244565    1
A   623946  Insertion   0.203704    NA
A   623491  Insertion   0.158358    NA
A   630788  None    0   0.714286
A   2215661 None    0.0625  0.230769

非常感谢您的宝贵时间。

最佳

0 个答案:

没有答案