how to change the format of file in R
2
0
Entering edit mode
19 months ago
sata72 • 0

I want to change the format of file from input to output (this is just an example of my data)

Input:

head(cpg_region2)
      cds       downstream     exon1       exons     intron1    introns      other    promoter            UTR3        UTR5
 1  1_47963035  1_68276036  1_47963035  1_47963035 1_33831751 1_33831751  1_32347715  1_48132522     11_18394188  1_68276036
 2  1_48088881  10_2648462 1_104414426  1_48088881 1_33831751 1_33831751  14_2527831  1_68276036     11_18394188  12_3142614
 3 1_168677980   12_396767 1_168677980  1_68276036 1_34481401 1_33831751  15_7112579  1_70154145      12_3134049 2_120841166
 4  10_2627156 14_12686663  12_3142614 1_104414426 1_48132522 1_33831751 17_10524429  1_70154145      13_9959153 20_13434035
 5  10_2627156 14_12686663  14_3960061 1_168677980 1_68276036 1_33831751  19_7740157 1_104414426      13_9959153   26_663159
 6  10_2627156  15_7007155 17_11003840  10_2627156 1_68276036 1_34188568   2_5702062 1_104414426      16_2178551   26_663159

Output

                  cds       downstream     exon1       exons     intron1    introns      other    promoter      UTR3      UTR5
 1_47963035        1              0          1           1          0          0           0       0            0        0
 1_48088881        1              0          0           0          0          0           0       0            0        0
 1_68276036        0              1          0           0          0          0           0       0            0        0
 .
 .
R • 810 views
ADD COMMENT
0
Entering edit mode
19 months ago
ATpoint 86k

It's basically the same as here: how to make a UpSet plot with data frame in R

ADD COMMENT
0
Entering edit mode
18 months ago
zx8754 12k

Reshape from wide-to-long - stack, then use table to get the counts:

as.data.frame.matrix(table(stack(cpg_region2)))

#            cds downstream exon1 exons intron1 introns other promoter UTR3 UTR5
#1_104414426   0          0     1     1       0       0     0        2    0    0
#1_168677980   1          0     1     1       0       0     0        0    0    0
#1_32347715    0          0     0     0       0       0     1        0    0    0
#1_33831751    0          0     0     0       2       5     0        0    0    0
ADD COMMENT

Login before adding your answer.

Traffic: 3000 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6