Difference between revisions of "Data.table"
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<h1><span style="font-family:courier new,courier,monospace">Convert a molten data table into an data table (array type)</span></h1> | <h1><span style="font-family:courier new,courier,monospace">Convert a molten data table into an data table (array type)</span></h1> | ||
− | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input</span></h3> | + | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input (head)</span></h3> |
− | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"> Species ID Var1 Var2 Val Group Print_name<br /> | + | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> Species ID Var1 Var2 Val Group Print_name<br /> |
1: Dendronephthya_gigantea g30906.t1.cds@g30906@000029F CDS_length Full 2.01600e+03 Non-symbiotic_cnidarian Carnation_coral<br /> | 1: Dendronephthya_gigantea g30906.t1.cds@g30906@000029F CDS_length Full 2.01600e+03 Non-symbiotic_cnidarian Carnation_coral<br /> | ||
2: Dendronephthya_gigantea g14782.t1.cds@g14782@000108F CDS_length Full 4.02000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | 2: Dendronephthya_gigantea g14782.t1.cds@g14782@000108F CDS_length Full 4.02000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | ||
3: Dendronephthya_gigantea g9986.t1.cds@g9986@000064F CDS_length Full 8.40000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | 3: Dendronephthya_gigantea g9986.t1.cds@g9986@000064F CDS_length Full 8.40000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | ||
4: Dendronephthya_gigantea g1279.t1.cds@g1279@000024F CDS_length Full 8.58000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | 4: Dendronephthya_gigantea g1279.t1.cds@g1279@000024F CDS_length Full 8.58000e+02 Non-symbiotic_cnidarian Carnation_coral<br /> | ||
− | 5: Dendronephthya_gigantea g9325.t1.cds@g9325@000042F CDS_length Full 8.61000e+02 Non-symbiotic_cnidarian Carnation_coral</span></div> | + | 5: Dendronephthya_gigantea g9325.t1.cds@g9325@000042F CDS_length Full 8.61000e+02 Non-symbiotic_cnidarian Carnation_coral</span></span></div> |
<h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> | ||
Line 18: | Line 18: | ||
<h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output</span></h3> | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output</span></h3> | ||
− | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"> ID CDS_length FPKM<br /> | + | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> ID CDS_length FPKM<br /> |
1: g10.t1.cds@g10@000002F 1185 30.363500<br /> | 1: g10.t1.cds@g10@000002F 1185 30.363500<br /> | ||
2: g100.t1.cds@g100@000002F 696 0.959006<br /> | 2: g100.t1.cds@g100@000002F 696 0.959006<br /> | ||
3: g1000.t1.cds@g1000@000011F 660 0.000000<br /> | 3: g1000.t1.cds@g1000@000011F 660 0.000000<br /> | ||
4: g10000.t1.cds@g10000@000064F 1074 0.278465<br /> | 4: g10000.t1.cds@g10000@000064F 1074 0.278465<br /> | ||
− | 5: g10001.t1.cds@g10001@000064F 522 0.962268 </span></div> | + | 5: g10001.t1.cds@g10001@000064F 522 0.962268 </span></span></div> |
+ | |||
+ | <h1><span style="font-family:courier new,courier,monospace">Fast melt for Data table</span></h1> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input (head)</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace"> Position G4-SV40 G4-SV40-OHT<br /> | ||
+ | 1: 101488764 52 51<br /> | ||
+ | 2: 101488765 52 50<br /> | ||
+ | 3: 101488766 52 49<br /> | ||
+ | 4: 101488767 53 49<br /> | ||
+ | 5: 101488768 54 49</span></span></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><big><span style="font-family:courier new,courier,monospace">melt(SeqDepth_dt, id.vars = "Position")</span></big></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output (head)</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace"> Position variable value<br /> | ||
+ | 1: 101488764 G4-SV40 52<br /> | ||
+ | 2: 101488765 G4-SV40 52<br /> | ||
+ | 3: 101488766 G4-SV40 52<br /> | ||
+ | 4: 101488767 G4-SV40 53<br /> | ||
+ | 5: 101488768 G4-SV40 54</span></span></div> | ||
+ | |||
+ | <h1><span style="font-family:courier new,courier,monospace">Data table aggregation with 'by'</span></h1> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input (head)</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> ID CDS_length FPKM ord bin<br /> | ||
+ | 1: g10.t1.cds@g10@000002F 10.210671 4.9242662 10665 8<br /> | ||
+ | 2: g10002.t1.cds@g10002@000064F 12.039262 2.3361320 3975 3<br /> | ||
+ | 3: g10008.t1.cds@g10008@000073F 9.162391 0.6201266 856 1<br /> | ||
+ | 4: g10011.t1.cds@g10011@000073F 9.942515 1.9781956 3149 3<br /> | ||
+ | 5: g10012.t1.cds@g10012@000073F 10.762382 0.5596289 785 1</span></span></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><big>dt[, .(Mean_CDS_length = mean(CDS_length), Mean_FPKM = mean(FPKM)), by=bin]</big></span></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> bin Mean_CDS_length Mean_FPKM<br /> | ||
+ | 1: 8 10.187520 4.7044951<br /> | ||
+ | 2: 3 10.590668 2.0831168<br /> | ||
+ | 3: 1 10.488467 0.4904325<br /> | ||
+ | 4: 4 10.550280 2.6412267<br /> | ||
+ | 5: 2 10.541246 1.3801430<br /> | ||
+ | 6: 7 10.344120 4.1326888<br /> | ||
+ | 7: 6 10.377043 3.6221557<br /> | ||
+ | 8: 10 9.563917 7.4570552<br /> | ||
+ | 9: 5 10.509382 3.1425986<br /> | ||
+ | 10: 9 9.941699 5.4668993</span></span></div> | ||
+ | |||
+ | <h1><span style="font-family:courier new,courier,monospace">Data table row-wise calculation</span></h1> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input (head)</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> Description ID Anolis_carolinensis Balaena_mysticetus Balaenoptera_acutorostrata_scammoni<br /> | ||
+ | 1: OG000001 OG000001 126 103 107<br /> | ||
+ | 2: OG000002 OG000002 70 19 48<br /> | ||
+ | 3: OG000003 OG000003 27 29 25<br /> | ||
+ | 4: OG000004 OG000004 39 36 47<br /> | ||
+ | 5: OG000005 OG000005 1 11 3</span></span></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><big>dt[,Sum := rowSums(.SD, na.rm=T), .SDcols = 3:5]</big></span></div> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><big>dt[,Mean := rowMeans(.SD, na.rm=T), .SDcols = 3:5]</big></span></div> | ||
+ | |||
+ | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output</span></h3> | ||
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace"><span style="font-size:11px"> Description ID Anolis_carolinensis Balaena_mysticetus Balaenoptera_acutorostrata_scammoni Sum Avg<br /> | ||
+ | 1: OG000001 OG000001 126 103 107 336 112.00000<br /> | ||
+ | 2: OG000002 OG000002 70 19 48 137 45.66667<br /> | ||
+ | 3: OG000003 OG000003 27 29 25 81 27.00000<br /> | ||
+ | 4: OG000004 OG000004 39 36 47 122 40.66667<br /> | ||
+ | 5: OG000005 OG000005 1 11 3 15 5.00000</span></span></div> |
Latest revision as of 12:39, 24 January 2019
Contents
Convert a molten data table into an data table (array type)
Input (head)
1: Dendronephthya_gigantea g30906.t1.cds@g30906@000029F CDS_length Full 2.01600e+03 Non-symbiotic_cnidarian Carnation_coral
2: Dendronephthya_gigantea g14782.t1.cds@g14782@000108F CDS_length Full 4.02000e+02 Non-symbiotic_cnidarian Carnation_coral
3: Dendronephthya_gigantea g9986.t1.cds@g9986@000064F CDS_length Full 8.40000e+02 Non-symbiotic_cnidarian Carnation_coral
4: Dendronephthya_gigantea g1279.t1.cds@g1279@000024F CDS_length Full 8.58000e+02 Non-symbiotic_cnidarian Carnation_coral
Code
Output
1: g10.t1.cds@g10@000002F 1185 30.363500
2: g100.t1.cds@g100@000002F 696 0.959006
3: g1000.t1.cds@g1000@000011F 660 0.000000
4: g10000.t1.cds@g10000@000064F 1074 0.278465
Fast melt for Data table
Input (head)
1: 101488764 52 51
2: 101488765 52 50
3: 101488766 52 49
4: 101488767 53 49
Code
Output (head)
1: 101488764 G4-SV40 52
2: 101488765 G4-SV40 52
3: 101488766 G4-SV40 52
4: 101488767 G4-SV40 53
Data table aggregation with 'by'
Input (head)
1: g10.t1.cds@g10@000002F 10.210671 4.9242662 10665 8
2: g10002.t1.cds@g10002@000064F 12.039262 2.3361320 3975 3
3: g10008.t1.cds@g10008@000073F 9.162391 0.6201266 856 1
4: g10011.t1.cds@g10011@000073F 9.942515 1.9781956 3149 3
Code
Output
1: 8 10.187520 4.7044951
2: 3 10.590668 2.0831168
3: 1 10.488467 0.4904325
4: 4 10.550280 2.6412267
5: 2 10.541246 1.3801430
6: 7 10.344120 4.1326888
7: 6 10.377043 3.6221557
8: 10 9.563917 7.4570552
9: 5 10.509382 3.1425986
Data table row-wise calculation
Input (head)
1: OG000001 OG000001 126 103 107
2: OG000002 OG000002 70 19 48
3: OG000003 OG000003 27 29 25
4: OG000004 OG000004 39 36 47
Code
Output
1: OG000001 OG000001 126 103 107 336 112.00000
2: OG000002 OG000002 70 19 48 137 45.66667
3: OG000003 OG000003 27 29 25 81 27.00000
4: OG000004 OG000004 39 36 47 122 40.66667