Related
I want to plot a split-violin plot as described here for each column of df (second column onwards). The x-axis would be subtype, and the fill is pathologic_stage.
My code returned "data must be a <data.frame>, or an object coercible by fortify(), not a character vector." error.
devtools::install_github("psyteachr/introdataviz")
library(introdataviz)
Plot:
for (i in 1:nrow(df[,-c(1:2)])){
print(ggplot(df[,i], aes(x=df$pathologic_stage, y=df[,i], fill=df$subtype)) +
geom_split_violin(alpha = .4, trim = FALSE) +
geom_boxplot(width = .2, alpha = .6, fatten = NULL, show.legend = FALSE) +
stat_summary(fun.data = "mean_se", geom = "pointrange", show.legend = F, position = position_dodge(.175)) +
scale_x_discrete(name = "Stage", labels = c("stage i", "stage ii", "stage iii", "stage iv")) +
scale_y_continuous(name = "Gene Expression", breaks = seq(200, 800, 100), limits = c(200, 800)) +
scale_fill_brewer(palette = "Dark2", name = "Subtype") +
theme_minimal())
}
Traceback:
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, not a
character vector.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/rlang_error>
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, not a
character vector.
---
Backtrace:
1. base::print(...)
3. ggplot2:::ggplot.default(...)
5. ggplot2:::fortify.default(data, ...)
Run `rlang::last_trace()` to see the full context.
Data:
dput(df[1:50,1:50])
> dput(df[1:50,1:50])
structure(list(pathologic_stage = c("stage i", "stage i", "stage i",
"stage i", "stage i", "stage iii", "stage i", "stage i", "stage i",
"stage i", "stage i", "stage iii", "stage i", "stage i", "stage i",
"stage i", "stage i", "stage i", "stage ii", "stage i", "stage i",
"stage i", "stage i", "stage i", "stage i", "stage iii", "stage ii",
"stage ii", "stage ii", "stage i", "stage i", "stage ii", "stage iv",
"stage iv", "stage i", "stage iii", "stage iv", "stage iv", "stage iii",
"stage iv", "stage i", "stage i", "stage i", "stage iii", "stage i",
"stage iii", "stage i", "stage i", "stage ii", "stage i"), subtype = c("KIRP",
"KIRP", "KIRP", "KIRP", "KIRP", "KIRP", "KIRC", "KIRC", "KIRC",
"KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRP",
"KIRP", "KIRP", "KIRP", "KIRP", "KIRP", "KIRP", "KIRP", "KIRP",
"KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRP", "KIRC",
"KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRC",
"KIRC", "KIRC", "KIRC", "KIRC", "KIRC", "KIRP", "KIRC", "KIRP",
"KIRC"), A1BG = c(66.4361, 39.6938, 77.9754, 53.1898, 191.8009,
50.8509, 12.4224, 28.5205, 80.5208, 19.1515, 53.2646, 21.3555,
33.4962, 42.2477, 16.9054, 58.6972, 35.6614, 109.9437, 14.429,
70.2027, 59.4344, 22.4731, 28.4957, 19.4994, 25.8724, 298.569,
148.3682, 139.7575, 61.7103, 220.857, 13.2709, 7.5077, 106.505,
129.3458, 28.7289, 80.3571, 18.543, 40.3925, 72.5155, 54.2779,
7.6608, 45.0186, 15.8792, 29.0844, 24.1362, 24.808, 127.0924,
51.6359, 16.2703, 40.4216), A1CF = c(0.374, 0.6125, 1.1703, 23.663,
2.9283, 47.0016, 126.8116, 316.5775, 315.9734, 190.5771, 127.0227,
335.9949, 59.898, 466.994, 595.8235, 136.7737, 0, 0, 0.7762,
86.9447, 0.9457, 12.178, 8.3199, 41.1204, 72.8039, 1.4406, 224.4191,
88.0664, 9.8863, 38.624, 5.9625, 271.4374, 5.5, 0, 106.4724,
73.3766, 168.3626, 6.6141, 141.568, 50.2988, 247.236, 36.9128,
173.1216, 42.394, 51.7409, 571.1754, 3.9402, 276.699, 0.6258,
171.743), A2BP1 = c(0, 1.2249, 2.3406, 0.4733, 5.8565, 1.6207,
0, 0, 0.3495, 0, 0, 0, 0.4248, 0.5456, 0, 0, 0.8703, 2.0471,
0.7762, 1.2938, 0, 0.4684, 0, 0, 3.6101, 1.9208, 0, 0, 0, 2.414,
2.1295, 1.2338, 1, 23.2415, 0, 0.6494, 1.8501, 0.7781, 0.564,
0.498, 0, 0.3729, 0, 0.3563, 0.9582, 0, 26.2683, 0, 0, 0), A2LD1 = c(53.1638,
150.1945, 175.7929, 133.7056, 90.0146, 220.5429, 189.9586, 1274.5478,
79.3569, 61.2079, 69.818, 62.3596, 247.3534, 73.4943, 211.3834,
118.192, 141.7798, 85.4555, 70.9227, 61.1951, 121.9658, 75.5082,
121.9032, 51.8594, 67.5331, 80.4898, 87.5234, 143.2993, 183.569,
147.924, 93.6542, 67.6619, 43.075, 37.83, 66.9431, 128.0065,
53.3858, 115.3026, 161.2126, 66.1355, 661.2867, 38.8255, 58.9311,
59.1628, 91.8562, 2430.7561, 50.8291, 142.4078, 74.3054, 187.11
), A2ML1 = c(0.374, 10.4119, 0, 0.4733, 0, 0.4052, 0, 1.426,
0, 0.3236, 0, 0, 0.8496, 0.5456, 0, 2.887, 0, 0, 0, 0.2588, 0,
0.9368, 0.416, 0, 1.2034, 0, 0, 0, 4.9432, 0.6035, 0, 0, 0, 0.447,
0, 1.9481, 0.9251, 1.9453, 1.128, 3.4861, 0, 0.3729, 0, 0.3563,
0, 2.3627, 0, 0, 4.3805, 0), A2M = c(29835.2992, 9396.2578, 10393.2768,
7446.9238, 22716.3543, 4080.9887, 14629.3271, 22602.4385, 27446.5851,
37196.4554, 53143.7176, 43071.7036, 42157.158, 36148.0142, 27739.0492,
19953.5583, 2267.7372, 48050.0768, 15309.9757, 11263.9665, 3457.7381,
6895.8267, 2168.5237, 6824.1776, 2439.627, 29292.8595, 33466.0932,
13926.7709, 10773.4355, 11296.4092, 13068.9566, 3865.4719, 19986.845,
7094.0991, 54466.2931, 44946.9091, 46699.9352, 7469.8126, 21914.4162,
26395.3586, 53265.4096, 41444.7614, 43623.3424, 38610.7374, 30405.7241,
19550.9096, 4950.5106, 57936.7379, 6543.7985, 66622.8908), A4GALT = c(1418.1002,
915.6331, 2365.7109, 2372.9295, 3014.6413, 802.269, 1449.2754,
1129.8871, 994.058, 1440.1676, 1554.2071, 1281.1242, 1143.5854,
1046.0993, 1333.0483, 1711.6564, 1312.8808, 2354.1453, 1895.4109,
1403.0185, 3031.7681, 1605.6206, 866.9336, 1641.2396, 2241.8773,
1029.0516, 1906.7916, 1368.2195, 1059.8122, 1135.7876, 365.4174,
1640.3455, 1205.5, 347.282, 1556.7386, 1881.8182, 1510.1758,
1173.413, 1451.7766, 863.5458, 1630.3648, 1073.8255, 1345.0813,
1833.274, 957.8463, 310.1004, 1830.2413, 1349.0291, 179.5995,
1475.9358), A4GNT = c(22.8123, 0, 2.3406, 5.6791, 5.8565, 4.8622,
27.9503, 32.7986, 45.4387, 28.7969, 33.1715, 25.5509, 10.1954,
20.4583, 17.3901, 67.4847, 2.611, 5.6295, 13.1949, 25.3589, 1.4185,
8.8993, 32.8636, 5.3635, 120.3369, 8.6435, 5.1354, 5.1053, 2.4716,
4.828, 0, 99.3214, 17, 0, 0, 6.4935, 42.0907, 15.5625, 44.5572,
27.3904, 11.8395, 2.2371, 0, 6.7688, 10.8592, 8.2693, 10.5073,
1.9417, 0, 8.0601), AAA1 = c(0.7479, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.8496, 0, 0, 0, 0, 0, 0, 0, 0.4728, 0, 0, 0, 0, 0.4802,
0, 0, 0, 0, 0.4259, 0, 1, 0.447, 0, 0, 0.4625, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), AAAS = c(624.1586, 746.5932, 1053.8327,
953.1472, 1301.6105, 1170.1783, 695.1346, 648.8414, 479.2031,
540.0224, 643.2039, 785.436, 622.3449, 581.2875, 607.2269, 850.5955,
1018.7119, 577.7892, 568.1576, 755.0734, 760.3062, 1000, 785.3986,
1072.1097, 1236.4621, 964.7059, 543.8439, 516.2731, 516.0652,
739.2879, 838.586, 1070.9439, 1093.5, 838.0356, 620.9022, 847.4026,
832.5624, 1299.4693, 1143.26, 890.9363, 554.714, 471.6629, 581.7196,
978.9811, 638.7771, 578.2634, 2372.0243, 498.5437, 754.6934,
487.9485), AACSL = c(0.374, 61.2464, 22.8204, 35.9678, 21.9619,
21.4749, 70.911, 84.1355, 67.1094, 37.2095, 23.0583, 21.7183,
8.921, 74.1953, 3.7061, 42.223, 15.6658, 1.5353, 33.7635, 24.0651,
1.4185, 53.8642, 24.5437, 48.8677, 80.0241, 3.3613, 49.3003,
2.5526, 18.784, 72.42, 3.4072, 42.5663, 43.5, 0, 8.2189, 16.8831,
40.7031, 7.3922, 25.9447, 32.8685, 82.8763, 100.6711, 17.8156,
46.669, 23.9541, 27.1707, 21.6713, 151.4563, 153.9424, 37.5107
), AACS = c(593.8669, 1303.3226, 813.9263, 739.7066, 740.8492,
1232.577, 271.7391, 391.6815, 510.3111, 603.7638, 473.301, 425.9342,
392.9482, 596.563, 556.4821, 852.7607, 1024.369, 663.7666, 881.3428,
798.8045, 708.768, 894.6136, 832.406, 1222.8844, 806.8592, 411.5246,
809.3465, 583.9183, 905.5858, 339.7707, 896.0818, 825.4164, 955,
586.178, 680.3026, 611.039, 567.5301, 1069.9223, 329.9492, 429.2829,
543.571, 424.3102, 319.907, 522.2658, 592.4658, 519.1967, 591.036,
640.7767, 546.9337, 390.2968), AADACL2 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.6035, 0, 0, 2, 0, 0.3736, 0, 0, 0, 0, 1.494, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), AADACL3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.4248, 0, 0, 0, 0, 0, 1.5523, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 3.5, 0, 0, 0, 0.4625, 0, 1.128, 0, 0, 0, 0,
0, 0.3194, 0, 0, 0, 0, 0), AADACL4 = c(0, 0, 1.1703, 0, 0, 0,
0, 0, 0, 0, 0, 0.2555, 0, 0, 0, 0, 0, 0, 105.1712, 0, 0, 0, 0,
0, 0, 0.9604, 0, 0, 0.4943, 1.8105, 0, 0, 0, 0.2235, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.4854, 0, 0), AADAC = c(0, 0,
0, 0, 0, 0, 0, 0.9507, 0, 0, 0, 38.3264, 0.4248, 0.2728, 1.9956,
0.3609, 0, 0, 11.6426, 0, 0, 0, 0, 0, 0.6017, 0.4802, 0, 1.2763,
0, 0, 2.1295, 0, 0.5, 0.2235, 2.6151, 257.7922, 0.4625, 0, 1.128,
3.9841, 0.3482, 0.7457, 0, 0.7125, 0, 0, 0.6567, 0, 0, 0), AADAT = c(68.0628,
124.3301, 70.8016, 45.433, 20.4978, 185.1702, 172.8778, 107.9026,
70.9542, 96.421, 63.9159, 99.9042, 162.7018, 66.8303, 104.3404,
77.2284, 100.9574, 34.8004, 10.0902, 39.8497, 188.6581, 68.3841,
127.2945, 85.8164, 106.4982, 81.1525, 22.0824, 35.0989, 104.7949,
65.178, 72.8279, 123.3806, 86.5, 126.9345, 61.6419, 107.7922,
149.3987, 49.411, 93.0626, 57.7689, 129.886, 122.2968, 80.945,
123.6195, 73.7788, 42.5281, 169.4303, 73.7864, 723.4043, 48.3608
), AAGAB = c(674.6447, 1476.0374, 985.9567, 1247.0421, 1244.5095,
826.5802, 702.381, 451.0992, 634.7431, 499.2538, 447.411, 531.4596,
856.4146, 494.2717, 666.8092, 576.6871, 1191.0357, 592.6305,
939.9437, 1205.064, 1584.444, 1091.3349, 1051.2194, 962.4553,
783.3935, 513.8055, 669.1488, 752.3931, 1244.1918, 553.4098,
2583.4753, 858.7292, 808, 1601.8772, 549.547, 498.0519, 508.7882,
542.7424, 393.683, 690.239, 510.1419, 413.1245, 472.8892, 722.1233,
1029.0699, 716.4796, 663.2737, 501.4563, 1657.0713, 434.0076),
AAK1 = c(732.2364, 1728.9848, 1579.2861, 1894.4628, 1161.0542,
2443.6791, 1035.1967, 1074.7475, 1162.5306, 1274.5046, 814.3204,
887.8952, 881.4783, 1433.1697, 1143.7531, 1019.4875, 1471.2794,
1201.6377, 1818.958, 1536.0232, 1534.3243, 1779.8595, 1978.0563,
1733.0155, 1841.1552, 1137.0948, 728.72, 565.4116, 1789.4217,
310.1992, 1095.8262, 1837.1376, 828, 1489.4687, 752.405,
947.4026, 827.012, 1209.9849, 956.5708, 1176.2948, 905.7195,
955.6301, 824.1673, 984.6812, 1169.6009, 1481.9846, 1195.206,
1325.7282, 1187.7347, 770.9835), AAMP = c(2327.5991, 3045.1692,
2152.7209, 2275.4378, 1932.6501, 3489.8703, 2151.1387, 1601.9014,
1656.0643, 1712.6055, 1910.5987, 2684.382, 1446.8989, 1904.5281,
1981.8972, 2886.6835, 1613.577, 1887.9222, 3891.336, 1933.4847,
2602.9138, 1873.0679, 1818.3142, 2419.5471, 1957.2804, 1505.4022,
3482.8604, 2273.1334, 1731.0924, 2270.9716, 1430.5792, 1304.7502,
3140.5, 1152.0197, 2074.1571, 1589.6104, 2739.1304, 2360.8323,
1771.0096, 2385.9562, 2149.5604, 1339.299, 2126.646, 3134.3071,
2141.5003, 2288.8364, 1322.6071, 1639.8058, 2118.8986, 2173.448
), AANAT = c(2.6178, 1.8374, 1.1703, 1.4198, 1.4641, 2.4311,
0, 0, 0, 0.6471, 0, 0.511, 0, 0.2728, 0, 2.1653, 0.8703,
2.0471, 0, 0.5175, 0.9457, 0.4684, 1.248, 1.1919, 0.6017,
2.401, 0.5135, 1.9145, 0.4943, 1.8105, 1.2777, 0.6169, 1.5,
1.3409, 0.3736, 0, 0.9251, 1.1672, 2.2561, 1.494, 0.3482,
0, 0, 0, 0.6388, 1.772, 1.3134, 0, 0.6258, 0.62), AARS2 = c(525.718,
641.2249, 668.8122, 645.9063, 680.8199, 584.2747, 262.412,
502.4219, 523.2366, 524.7859, 475.2063, 464.9505, 246.8097,
561.6312, 422.7582, 626.817, 455.544, 327.5128, 570.4589,
599.0258, 477.0827, 659.9485, 618.9923, 541.1144, 422.3827,
400.9604, 409.2952, 205.4882, 560.0445, 232.3476, 497.0017,
478.6798, 623.49, 387.0049, 305.2059, 779.6818, 662.8076,
341.1963, 681.6977, 750.9861, 588.46, 527.9605, 612.6995,
425.7214, 452.5736, 596.5682, 743.3328, 487.3544, 555.6946,
417.878), AARSD1 = c(597.9806, 989.7412, 1583.9672, 924.7515,
2733.5286, 754.8622, 638.1988, 520.4991, 611.3247, 399.5972,
499.1909, 679.9106, 383.1776, 468.6307, 386.8577, 765.7885,
787.6414, 442.6817, 580.1882, 414.7987, 620.3493, 666.5105,
697.2076, 641.8355, 707.5812, 652.1008, 690.7177, 636.8858,
348.4923, 601.6898, 353.9182, 562.6157, 708, 286.273, 586.1586,
728.5714, 735.4302, 1082.3723, 866.8923, 628.9841, 413.3368,
590.9769, 653.3695, 804.0613, 838.0756, 341.4058, 1069.1184,
433.0097, 473.0914, 541.5795), AARS = c(1833.2087, 3809.5238,
4739.0287, 3400.8519, 3606.1493, 2477.7147, 1309.5238, 1984.0761,
2380.6361, 2323.8112, 2363.2686, 2918.4286, 2183.9422, 2660.3928,
2749.3407, 2912.306, 4083.1158, 2761.5148, 2589.6963, 3280.8689,
3703.6555, 3992.5059, 3298.0084, 3389.7497, 1912.7557, 1920.2881,
2473.2315, 1499.6809, 2709.8369, 1821.3639, 3267.4617, 2870.4503,
3894, 3654.9528, 3225.927, 2321.4286, 2848.7512, 7012.0765,
1807.1066, 2709.6614, 3043.7886, 2310.2163, 2445.0039, 4618.0976,
4203.7923, 2442.4099, 1290.4285, 2641.2621, 2016.2703, 3129.8148
), AASDHPPT = c(790.5123, 1154.494, 666.2493, 776.1477, 342.6061,
1030.7942, 1660.4555, 907.9026, 1339.0423, 1158.67, 984.2233,
1213.9253, 1235.7689, 1284.2335, 1423.7047, 755.9906, 1221.497,
786.5916, 1135.9115, 981.7507, 855.3444, 943.2881, 1168.53,
1003.5757, 625.1504, 609.3637, 1113.8785, 1341.4167, 1309.9357,
1214.2426, 661.8399, 617.52, 948.5, 997.5798, 1234.2991,
797.4026, 1054.0703, 504.2252, 668.3587, 882.4701, 964.2204,
1136.4653, 1102.6336, 1217.638, 1085.2823, 1321.9138, 406.5014,
983.4951, 833.5419, 1053.7084), AASDH = c(214.2857, 250.4976,
148.6249, 229.0582, 121.5227, 257.2934, 277.9503, 295.1872,
262.1461, 329.061, 267.3948, 253.4653, 361.9371, 288.3252,
283.0874, 209.3107, 219.7563, 219.0379, 387.6977, 214.5154,
322.4682, 212.6464, 203.8376, 199.6424, 116.1252, 106.6026,
238.7983, 96.3625, 247.1577, 153.2891, 362.862, 140.037,
220.5, 347.0585, 223.4052, 157.7922, 192.4144, 62.25, 159.0525,
171.8127, 301.9065, 266.2192, 260.2634, 161.7385, 187.4811,
193.1483, 289.6076, 233.4951, 317.2716, 226.924), AASS = c(427.0755,
305.0069, 473.3762, 1046.8528, 266.4714, 1009.7245, 414.0787,
675.4605, 589.654, 367.5647, 453.8835, 310.1884, 880.2039,
700.7638, 1040.5531, 228.0765, 1614.4473, 283.0092, 468.8076,
392.545, 515.3817, 684.3091, 888.5653, 816.4482, 2000, 418.2473,
209.0127, 58.7109, 551.656, 441.7622, 566.4395, 2349.1672,
294, 223.6996, 238.7223, 533.1169, 534.2276, 253.6689, 1132.5437,
457.1713, 328.7194, 469.0529, 416.7312, 217.6701, 276.9099,
142.9415, 2046.2978, 207.2816, 451.8148, 400.527), AATF = c(1334.3306,
1346.1951, 1459.9181, 1310.9323, 1692.5329, 1314.4246, 1440.9938,
1126.5597, 1240.1258, 913.7347, 1110.0324, 1635.2603, 745.5395,
1126.2957, 844.4159, 1340.6712, 860.3133, 1223.132, 2095.6631,
941.901, 1384.4381, 1051.5222, 1034.1636, 1017.2825, 836.3418,
1105.8824, 1010.6561, 570.5169, 847.7509, 656.6083, 551.9591,
1179.5188, 1446.5, 964.7466, 1332.5862, 991.5584, 1271.5079,
3250.2295, 1002.2561, 1498.008, 1168.6254, 1619.3139, 1367.1572,
1391.8774, 1324.185, 1135.8535, 1058.6111, 1287.3786, 1419.8999,
1453.6154), AATK = c(127.5243, 14.6991, 12.873, 8.992, 5.8712,
15.3971, 54.3478, 95.0683, 86.3334, 95.7739, 337.3786, 106.8029,
120.2209, 161.0038, 91.5117, 153.8217, 3.4813, 117.1955,
17.4639, 6.2103, 18.9131, 7.4941, 9.5679, 25.0298, 8.4236,
80.1921, 58.0306, 40.2042, 15.8181, 132.1666, 35.3492, 30.8452,
41, 53.1873, 74.7175, 281.3182, 181.3136, 41.6297, 283.1359,
118.0279, 46.6614, 77.9269, 206.8164, 134.7667, 37.3685,
46.6627, 9.8506, 145.6311, 43.8048, 162.7528), ABAT = c(142.1092,
846.4247, 1145.1141, 1233.7908, 563.6896, 5905.1864, 1161.4907,
360.7843, 339.0423, 480.1637, 239.0777, 633.1523, 234.4945,
718.767, 3055.2348, 166.3659, 2442.9939, 83.4186, 34.9277,
2107.8917, 1005.7035, 1555.0351, 3974.8323, 1581.6448, 2007.2202,
258.8235, 232.1222, 709.6362, 2171.5274, 642.7278, 809.6252,
3375.694, 207.5, 254.0924, 104.6045, 562.987, 391.7669, 263.0064,
881.5567, 639.4422, 703.0556, 144.6682, 386.9094, 1405.415,
836.798, 346.1311, 193.7285, 328.6408, 4592.6158, 233.1241
), ABCA10 = c(23.2199, 9.7994, 7.0217, 19.4037, 7.3206, 17.0178,
23.8095, 48.4848, 19.5841, 23.2964, 19.0129, 34.5193, 22.5149,
35.7774, 11.9735, 24.908, 10.4439, 7.6766, 22.8971, 8.798,
23.6414, 3.7471, 8.7359, 7.7473, 9.627, 31.6927, 3.0813,
0, 1.9773, 65.7815, 52.385, 8.6366, 20, 12.7381, 5.6038,
44.1558, 68.4551, 5.4469, 154.5685, 24.4024, 7.3126, 50.3356,
8.1332, 3.2063, 3.5133, 1.1813, 105.0731, 7.2816, 692.8661,
3.1001), ABCA11P = c(58.1862, 93.9335, 27.7882, 59.1671,
38.6091, 48.9425, 65.9834, 80.1806, 87.3471, 70.9439, 118.1594,
57.7962, 116.7842, 90.6137, 58.6558, 56.6402, 24.2776, 45.5937,
83.2871, 46.6319, 82.6928, 34.8197, 51.2215, 51.9249, 68.1528,
69.2341, 36.0149, 28.6918, 36.871, 113.8443, 83.7095, 47.3288,
81.95, 62.2493, 35.7037, 119.5779, 104.7086, 51.7842, 93.5759,
133.2769, 35.0205, 100.3691, 73.993, 29.1557, 61.6516, 38.4406,
217.0087, 58.5, 347.7597, 76.5558), ABCA12 = c(11.5931, 124.3301,
89.526, 141.0317, 178.6237, 1205.0243, 120.6004, 220.0832,
99.266, 252.7007, 67.9612, 665.602, 160.1529, 25.9138, 95.2177,
123.0603, 57.8764, 22.5179, 553.0222, 752.7445, 42.5544,
530.2108, 396.8592, 471.9905, 11.432, 85.9544, 6.6761, 15.3159,
665.3485, 255.8841, 4.2589, 14.1888, 38, 2.0113, 98.6271,
84.4156, 413.9685, 66.1407, 73.3221, 33.8645, 104.4659, 83.5198,
266.8474, 352.3335, 248.8037, 1377.4365, 6.5671, 80.5825,
51.3141, 66.0312), ABCA13 = c(25.4301, 1.2249, 12.873, 0,
5.8565, 0, 2.0704, 0, 0.3495, 0.9707, 0, 1.022, 4.6729, 0.5456,
3.9912, 4.6914, 6.0923, 28.6592, 541.3796, 112.3036, 4.2554,
14.0515, 22.8797, 4.7676, 361.0108, 0.4802, 0.5135, 0, 17.301,
1.8105, 16.6099, 22.2085, 10.5, 9.386, 0.7472, 1.2987, 4.1628,
0, 2.2561, 25.3984, 1.0447, 0, 1.5492, 0.7125, 69.6267, 1.772,
11.8207, 1.9417, 41.9274, 0.31), ABCA17P = c(36.2752, 12.8617,
8.7771, 4.7326, 1.4641, 29.5786, 36.2319, 13.7849, 17.8259,
10.0304, 4.4498, 26.8285, 12.3195, 4.0917, 2.5657, 39.336,
8.2681, 9.7236, 102.4546, 17.0784, 8.9837, 3.7471, 3.328,
4.1716, 5.4152, 13.4454, 4.6219, 16.5922, 4.4488, 89.318,
19.1652, 1.2338, 42.5, 23.2415, 5.9774, 42.8571, 37.9278,
12.45, 671.1788, 46.3147, 20.1967, 18.6428, 4.6476, 8.9063,
6.3878, 25.3987, 19.0445, 23.7864, 1.2516, 12.0902), ABCA1 = c(378.7509,
1455.1891, 1033.3528, 1713.6346, 856.5154, 2420.0324, 900.0776,
6174.8782, 2993.3555, 5553.7859, 1983.3738, 3218.343, 1494.0357,
3179.1135, 3256.4806, 2258.1992, 1283.2768, 461.1054, 877.0505,
2667.3136, 670.9276, 1710.5012, 1582.4284, 1420.7211, 1433.8147,
1946.1945, 1939.1295, 1381.6209, 3498.7296, 1465.9022, 2007.5128,
917.9272, 1577.985, 3137.639, 3958.8568, 3062.8312, 1044.3663,
1159.399, 2689.1371, 1853.0378, 2365.77, 3466.0291, 1497.2657,
913.0638, 2721.4748, 2339.622, 486.6196, 2814.034, 498.1227,
1388.4926), ABCA2 = c(4267.3897, 1250.0383, 1385.6056, 1640.7951,
1060.0293, 1760.5348, 942.029, 2243.1373, 2808.8081, 1837.1763,
2047.7346, 1324.0498, 954.9703, 1930.9875, 1299.4085, 3079.0328,
1367.7111, 1968.782, 1856.6023, 2517.5151, 3804.8406, 1973.7705,
2435.6508, 1859.9523, 1364.0193, 1726.2905, 1586.8533, 479.8979,
1128.0277, 1065.178, 1576.661, 907.4645, 1307.5, 1616.4032,
1230.9704, 1818.1818, 1482.4237, 433.4158, 1600.6768, 1769.9203,
1440.585, 2171.8867, 1596.4369, 868.5429, 1585.4448, 746.013,
2508.6193, 3495.1456, 458.6984, 1278.4624), ABCA3 = c(1893.4181,
1465.013, 3856.0562, 3091.3393, 3431.918, 2689.222, 3052.795,
2074.391, 2635.7917, 1536.5886, 1269.0129, 2005.2379, 823.7043,
1402.0731, 1331.3378, 2961.7467, 3307.6588, 924.7697, 1757.6404,
2490.8624, 1433.1393, 4549.4145, 3365.3996, 2532.1812, 1309.2659,
1638.8956, 1541.1478, 1419.2725, 1534.8492, 1106.2161, 882.0273,
1491.0549, 2005, 446.2819, 1206.6872, 1635.0649, 1496.7623,
2689.9793, 1532.4309, 2035.8566, 1663.4456, 1413.8702, 570.1007,
1497.6844, 2466.3185, 3694.0343, 1451.3216, 2634.9515, 56.9462,
1292.4126), ABCA4 = c(881.825, 3.0623, 0.5851, 0.9465, 1.4641,
2.0259, 3.6232, 6.1794, 4.1943, 5.5005, 11.3269, 6.8988,
22.5149, 3.8189, 5.9867, 2.887, 0, 263.5619, 580.9644, 2.0701,
1.4185, 0.4684, 1.248, 0, 3.0084, 7.2029, 1.5406, 0.6382,
3.4602, 4.828, 9.7956, 1.2338, 2.5, 22.7946, 5.6038, 26.6234,
3.7003, 106.9922, 6.7682, 12.9482, 4.5269, 4.1014, 7.7459,
2.85, 4.1521, 0.5907, 0.6567, 9.2233, 41.3016, 7.7501), ABCA5 = c(730.7068,
355.2289, 297.835, 539.044, 169.8389, 378.0389, 890.2692,
849.4355, 726.6585, 900.4688, 439.7249, 792.3092, 627.0178,
741.3639, 399.9715, 631.1729, 644.0383, 318.3214, 267.003,
248.931, 560.3002, 385.4801, 394.3633, 402.2646, 486.7629,
650.6603, 523.3021, 232.291, 467.6223, 947.4955, 1552.8109,
475.0154, 348.5, 857.925, 399.7385, 816.8831, 1063.3673,
122.5547, 1443.2882, 478.5857, 454.4267, 679.3438, 608.4431,
327.0395, 310.4457, 282.9297, 1832.2115, 695.6311, 646.3079,
379.4466), ABCA6 = c(10.0972, 20.8238, 32.1826, 26.0293,
2.9283, 5.2674, 8.7992, 62.7451, 15.0297, 26.532, 47.7346,
17.3746, 44.6049, 56.192, 28.7934, 32.4792, 50.0435, 6.653,
219.6565, 98.5891, 7.0924, 11.2412, 18.7198, 36.3528, 4.2118,
32.1729, 3.5948, 40.2042, 7.4147, 32.589, 43.4412, 5.5521,
47, 4.0226, 66.4986, 38.3117, 18.5014, 11.2828, 43.9932,
32.3705, 44.2239, 76.4355, 23.6251, 6.4125, 439.4787, 552.2741,
42.0292, 213.1068, 20.6508, 8.0601), ABCA7 = c(142.8571,
464.2474, 815.6817, 783.7198, 1194.7291, 406.8071, 93.6853,
182.5312, 189.4443, 262.084, 198.6246, 196.4867, 104.9278,
390.3437, 84.6697, 328.4013, 358.5727, 345.957, 497.1379,
375.4666, 387.2455, 699.2974, 670.168, 538.1406, 419.3742,
1285.9544, 160.226, 49.1385, 498.2699, 106.8196, 255.5366,
302.8994, 183.5, 402.4806, 134.865, 348.0519, 221.0916, 723.6566,
329.9492, 839.1434, 90.8853, 133.1096, 60.031, 87.2818, 304.3773,
69.1081, 919.3893, 129.6117, 234.6683, 86.1815), ABCA8 = c(80.0299,
358.2912, 31.0123, 701.3725, 125.9151, 3.6467, 6.2112, 119.3108,
1.3981, 62.4472, 100.3236, 49.0578, 136.3636, 178.6688, 118.0244,
69.6499, 29.5909, 23.0297, 194.431, 147.7543, 49.174, 44.9649,
1329.1041, 1386.77, 359.8075, 36.9748, 13.3522, 33.8226,
879.387, 80.2655, 121.8058, 77.1129, 42, 17.8781, 206.2202,
5.8442, 149.8612, 16.7297, 75.0141, 14.4422, 167.4937, 105.1454,
263.749, 42.394, 83.6798, 2.3627, 283.6973, 59.2233, 150.8135,
142.9125), ABCA9 = c(8.2274, 11.6368, 17.5541, 8.992, 2.9283,
11.3452, 35.7143, 50.3862, 30.7585, 21.6786, 45.712, 28.106,
64.1461, 60.0109, 41.6221, 32.8401, 7.3977, 4.0942, 58.989,
15.5258, 15.6033, 3.2787, 1.664, 8.3433, 4.2118, 45.1381,
1.0271, 19.783, 0, 21.726, 52.385, 0, 51.5, 2.0113, 32.5021,
104.5455, 51.3414, 14.3953, 137.6199, 49.8008, 21.9378, 87.994,
13.9427, 8.5501, 63.2389, 2.3627, 51.2231, 12.6214, 15.0188,
3.1001), ABCB10 = c(429.6933, 408.5132, 263.3119, 309.0393,
207.9063, 521.8801, 893.3747, 526.6786, 503.3205, 626.0895,
475.3236, 646.4388, 565.4206, 413.257, 858.9552, 415.0126,
525.2393, 384.3398, 446.6867, 449.4731, 384.4085, 529.7424,
388.9553, 386.174, 250.3008, 412.485, 457.0548, 532.8653,
458.2304, 828.0024, 251.2777, 212.8316, 434.5, 269.7357,
502.1014, 401.9481, 508.7882, 380.8924, 271.8556, 371.0159,
690.5197, 423.5645, 488.3811, 440.684, 412.0112, 805.0797,
262.6826, 549.5146, 409.2616, 505.3088), ABCB11 = c(0, 0.6125,
0, 0, 0, 0, 0, 0, 0, 0.6471, 0, 2.8106, 0.4248, 0.8183, 0.2851,
0, 0, 0.5118, 6.9855, 0.5175, 0, 0.4684, 0, 0.5959, 0, 0,
0.5135, 0, 0.4943, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.564, 0, 0,
0.3729, 0, 0, 0, 0, 0, 0.9709, 0, 0), ABCB1 = c(83.3957,
410.9631, 1382.0948, 3798.8642, 2136.164, 6457.4554, 1570.911,
634.1058, 871.7232, 947.385, 383.8997, 779.0482, 852.1665,
1000, 2371.8908, 1003.2479, 426.4578, 100.8188, 3182.6914,
1995.8468, 107.8046, 8507.26, 3411.1591, 2440.4052, 5239.4705,
354.8619, 1671.0746, 183.1525, 1926.8413, 654.1943, 399.4889,
4606.4158, 796.5, 73.7471, 738.5822, 312.987, 518.0389, 5323.9336,
403.8353, 109.5618, 967.3544, 470.5444, 341.5957, 432.8465,
2066.1246, 2427.6432, 3770.1527, 1274.7573, 84.4806, 75.3313
), ABCB4 = c(14.5849, 39.8101, 25.7461, 62.4704, 177.1596,
97.6499, 219.9793, 21.8657, 14.3307, 49.8283, 25.89, 47.7803,
29.7366, 29.7327, 39.6265, 137.4955, 17.4064, 29.1709, 16.6877,
152.1532, 1.4185, 76.815, 233.3732, 392.1335, 320.0963, 91.2365,
97.5735, 17.2304, 42.0168, 12.6735, 9.7956, 133.868, 208,
6.4808, 41.4682, 195.4545, 6.013, 272.7329, 175.4089, 36.3546,
16.0181, 18.6428, 35.6313, 18.8814, 105.3982, 515.6527, 199.6388,
516.9903, 2.5031, 288.9251)), row.names = c("TCGA-2Z-A9J9-01A",
"TCGA-2Z-A9JO-01A", "TCGA-2Z-A9JP-01A", "TCGA-2Z-A9JR-01A", "TCGA-2Z-A9JT-01A",
"TCGA-5P-A9JU-01A", "TCGA-A3-3306-01A", "TCGA-A3-3322-01A", "TCGA-A3-3324-01A",
"TCGA-A3-3331-01A", "TCGA-A3-3349-01A", "TCGA-A3-3352-01A", "TCGA-A3-3365-01A",
"TCGA-A3-3370-01A", "TCGA-A3-3373-01A", "TCGA-A3-A6NI-01A", "TCGA-A4-7584-01A",
"TCGA-A4-7828-01A", "TCGA-A4-7915-01A", "TCGA-A4-7997-01A", "TCGA-A4-8312-01A",
"TCGA-A4-8517-01A", "TCGA-A4-8630-01A", "TCGA-A4-A4ZT-01A", "TCGA-A4-A5DU-01A",
"TCGA-AK-3426-01A", "TCGA-AK-3429-01A", "TCGA-AK-3451-01A", "TCGA-AK-3456-01A",
"TCGA-AK-3458-01A", "TCGA-AK-3465-01A", "TCGA-AL-3468-01A", "TCGA-B0-4691-01A",
"TCGA-B0-4699-01A", "TCGA-B0-4823-01A", "TCGA-B0-4843-01A", "TCGA-B0-4845-01A",
"TCGA-B0-5084-01A", "TCGA-B0-5085-01A", "TCGA-B0-5092-01A", "TCGA-B0-5119-01A",
"TCGA-B0-5120-01A", "TCGA-B0-5693-01A", "TCGA-B0-5696-01A", "TCGA-B0-5697-01A",
"TCGA-B0-5701-01A", "TCGA-B1-A47N-01A", "TCGA-B2-5633-01A", "TCGA-B3-4104-01A",
"TCGA-B4-5834-01A"), class = "data.frame")
Desired output (sample):
I have the following data frame that I'd like to aggregate all the values in the data column (a table in this nested data frame), and then mutate 6 corresponding variables in the df.test to save these values.
structure(list(Unipro.ID = c("Q13177", "Q8TD19"), Gene.name = c("PAK2",
"NEK9"), Mod.site = c("Q13177_278", "Q8TD19_81"), Mod.site2 = c("PAK2_278",
"NEK9_81"), `mod.or.not(Y/N)` = c("Y", "Y"), `kinase.or.not(Y/N)` = c("Y",
"Y"), data = list(structure(list(`First Scan` = c(18638, 18640,
18699, 18889, 18890, 19117, 19277, 19387, 19395, 19495, 19502,
19576, 19650, 19726, 19802, 19879, 19956, 20034, 20111, 20189,
20266, 20342, 20420, 20497, 20574, 20670, 20727, 20803, 20918,
20956, 21033, 21147, 21185, 21263, 21377, 21416, 21492, 21607,
21646, 21762, 21840, 21879, 21994, 22072, 22113, 22240, 22298,
22356, 22473, 22530, 22703, 22760, 22820, 22936, 23012, 23165,
23243, 23281, 23396, 23472, 23572, 23590, 23665, 23741, 23760,
23894, 23970, 23990, 24122, 24200, 24372, 24428, 24568, 24605,
24661, 24702, 24860, 25051, 25116, 25457, 25459, 25470, 25522,
25806, 26042, 26288, 26516, 27123, 27344, 27573, 27867, 28024,
28224, 29830, 30443, 32854), TMT126 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 683.603289421257, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1058.63721546934, 5105.06075558397, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 786.877999584963, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1158.61443528477, 0, 0, 0, 0, 0, 790.552967308115,
1769.24251582031, 0, 0, 4230.5333458008, 0, 754.027149866911,
0, 0, 937.667214973757, 0, 0, 16065.4787548108, 0, 1033.79325384522,
0, 1545.17012178734, 22490.6473715619, 0, 12391.863457809, 1694.80635977683,
1669.92554702357, 2915.19207246094, 1305.76068893333, 1218.70367092158,
1724.48555844726, 1220.71902820389, 1142.29342043404, 15089.1510828024,
786.642299340822, 0, 0, 803.014098225646), TMT127N = c(0, 0,
0, 0, 0, 0, 0, 865.592199462889, 0, 0, 959.490090490725, 0, 0,
0, 3632.481907304, 0, 0, 0, 0, 0, 2281.36683418381, 0, 0, 1148.88409380685,
2282.96815473633, 0, 737.964767776176, 0, 0, 714.336386722035,
1336.78857436523, 0, 992.266982382272, 0, 8167.51299697265, 1481.83583737793,
0, 0, 0, 0, 0, 994.583403515622, 0, 3822.09582135578, 730.363546764861,
0, 0, 1601.84151123047, 0, 0, 0, 0, 1248.0926793457, 0, 2349.57136347657,
0, 925.784469760195, 0, 0, 0, 0, 0, 0, 0, 2869.82125708008, 779.87640303955,
0, 4092.33059296876, 0, 0, 0, 1133.40195924235, 0, 0, 0, 15684.5063332031,
0, 0, 0, 2583.52765913085, 24540.0170683595, 1238.62926386719,
11428.895775, 1483.56418256835, 1332.67443391114, 1825.25018671875,
1123.61925747071, 1030.31205838623, 1533.51140185547, 2153.17955595703,
1008.89100509033, 12831.9995203125, 1684.62781442872, 0, 1136.51165412598,
0), TMT128C = c(1611.91088437501, 1786.68805515069, 0, 1823.53765170799,
874.032758349609, 0, 0, 1177.50190689896, 646.466474431654, 1499.41582602539,
1255.4240426748, 1783.93500465848, 5996.15327152243, 8208.12153691405,
21348.7184882813, 33456.1981237878, 46046.4520991817, 5945.01241588586,
6798.69927773436, 18048.0166453125, 3490.51877753905, 7744.45986702618,
11529.8069519532, 3396.17701757812, 4651.27894687501, 14325.2306858641,
1561.40410561524, 0, 9592.47815625001, 2089.33504892578, 3367.76334082031,
10669.6799841273, 1439.18170268554, 0, 9310.75753007808, 1700.90959455201,
0, 6206.48464218753, 3397.72012818408, 0, 7079.64974935495, 1845.17109756826,
1177.34360229492, 6097.26335625001, 1754.74566738282, 1392.17984296875,
7026.71143068691, 2193.1615467585, 2836.98221749547, 6301.54294276034,
0, 3623.93436796874, 1312.70517940113, 0, 4724.16524276671, 0,
3946.52595689374, 2970.83282951206, 865.842519287108, 3283.01703994418,
0, 0, 1262.2417984723, 3482.3909258789, 4262.98461721732, 725.868942626953,
3139.75638657914, 6559.00482506506, 719.443235961914, 1980.26911301631,
735.412520327744, 2538.58699423828, 0, 0, 3345.73545624628, 17476.7195602775,
0, 3061.52193035407, 0, 3370.09478829905, 23476.7103351433, 1087.0128899699,
11912.6099077086, 1957.73038989257, 3158.21345361328, 3399.21823401529,
2593.01804501953, 934.40066220703, 2667.04373535038, 2390.35165488282,
1286.71902949219, 13590.0106023424, 1817.04336728435, 720.287557226125,
916.984646430313, 0), TMT129N = c(5236.22537109374, 5253.53062265625,
2574.52071173515, 6331.35667763673, 2909.4254578125, 2260.77584003907,
2299.19597588428, 2146.42980395508, 1524.82949099121, 4594.55742216798,
2945.06894956055, 3353.94465205077, 17265.8083640626, 58543.518953906,
42651.7719375001, 85288.5246984373, 147283.5420375, 16268.584838086,
31273.8547945313, 64984.9260843748, 15376.6111124999, 18807.9172359374,
41234.0440359375, 7038.37527421877, 14994.4310613281, 35007.7380726561,
5527.67209306639, 8827.66559818178, 32485.2518203124, 6771.8957270508,
10744.4285308594, 21706.4754328126, 7351.69939775389, 7286.74206159669,
31413.8810906249, 5402.31355253905, 7530.87224590352, 22346.2738640626,
7845.50157832029, 8598.84479102795, 13646.5870857421, 3948.41240126953,
4709.55193242188, 14502.506803125, 5527.37162548826, 4609.58657929687,
17346.4145701172, 3806.28572124023, 6695.23604707033, 10312.3288382812,
5030.34046109047, 12238.5130183594, 4008.11956391603, 3366.81581267473,
10163.4030287109, 5657.196356792, 9102.44150449222, 3997.46163222657,
3410.17096083986, 7459.02988359372, 2817.01574699993, 3228.9395395409,
1668.4944914795, 8344.1621935547, 6186.76663623048, 4037.21344028321,
4953.59359042969, 6163.53660527345, 2403.32564355468, 7143.26629951174,
1674.84291965332, 6149.94359912111, 2371.20030146484, 2708.46439392749,
8739.23083300782, 17708.4475347656, 2940.52380873895, 6755.28018515623,
2318.903026372, 5194.7135689453, 37003.6496414061, 1967.3172459961,
11835.060703125, 6357.79309687501, 6929.07336386721, 4922.18842499999,
5119.39548720702, 5098.90275791014, 5251.26713525389, 3925.45210825196,
3679.82248959962, 14610.4555587891, 3124.13869614258, 1892.91264873047,
2424.18607792969, 1217.02803508301), TMT130C = c(8534.51942065459,
7915.5220132809, 5427.32003829632, 6570.76122664215, 4059.66840776324,
6061.80182135341, 4680.93892861494, 3924.40329255471, 1651.02954082353,
9963.97493859979, 2095.70639501953, 6791.52962729408, 29089.1005494669,
84188.5986999335, 79102.1477485965, 111076.559352845, 228355.265937366,
31033.9549731673, 34443.9266034838, 100401.13011289, 20754.0266423186,
29334.7579023722, 70572.5366141732, 12419.2333360566, 17842.2049581652,
61518.6150214895, 10110.7438562966, 17502.4708992952, 61357.4708251869,
9995.86560411634, 17530.0854369149, 53203.79872126, 11560.0754183956,
13608.3534926174, 46828.7269257867, 11019.0036476036, 12751.4728461078,
26876.5493340097, 15817.3356058367, 13322.0303678209, 28346.2564980389,
6207.28749858749, 9509.23448457102, 36589.1961503305, 10263.6194964664,
7564.4130620443, 29223.5021208951, 7015.27604618795, 8985.64276558643,
18886.2813530505, 7104.5605795249, 17804.4468985063, 6812.45760606556,
6606.50436956103, 18488.5028791766, 5863.36827860186, 13255.0296116594,
6453.52502342659, 5515.76995189115, 13991.8058338637, 3809.92839574631,
5061.53991882257, 5991.94758913396, 11334.5748098943, 6206.71330898436,
5219.26272399663, 10963.7722168793, 7489.68230742191, 3361.11015884112,
9301.91002246388, 2802.03791217282, 10320.7319848397, 2509.93049810913,
3062.67670544402, 12115.818468418, 22596.7672476562, 5210.67744771832,
12678.5528095273, 3674.33047767757, 10158.3722420368, 38620.8279703125,
4299.66130273203, 16002.3112734375, 9597.19786319193, 10816.7672483378,
10449.5441895035, 8882.17509875803, 5726.84640941102, 8043.21098886215,
7002.83669129089, 4997.59224291582, 17214.8268832032, 4203.51644882184,
2044.40880964859, 2570.59274774035, 1621.14734118819), TMT131 = c(9418.17036445313,
8878.68274218749, 8378.77222617187, 5645.64330000002, 4753.99889121092,
4420.32600410157, 5180.99550117188, 4787.09710488281, 4537.51669335937,
11573.2264957031, 3011.21359365234, 6855.67281093751, 33135.919678125,
78639.2005781249, 89222.1922968751, 117395.8545375, 221719.7701125,
31420.3548656251, 46548.5491968752, 99822.2995687501, 21221.19759375,
31903.8316523437, 65884.2084140624, 12792.6073300781, 32494.3474710937,
55493.9358187499, 10832.2051148437, 16887.821878125, 56011.2740859373,
11016.5575394531, 15928.4518980469, 45726.2466890625, 10025.5855992188,
21737.7840796876, 59706.8427656249, 9716.2620714844, 18071.6204882813,
35495.48536875, 19939.4042976562, 13032.988340625, 32501.3787140625,
7199.69156542971, 10150.1181632812, 40466.1293437499, 10645.1514984375,
11109.5601890625, 28522.8374835938, 5834.91936972658, 6796.13434628906,
23190.480225, 9266.24059453124, 29075.5950890626, 7621.3969927734,
9322.90506210938, 22800.4644656249, 7069.82396484372, 15978.9590683593,
6530.85736874999, 6011.4814611328, 17323.3141382813, 4554.70168183593,
5415.33720234375, 6123.79340332032, 14385.484575, 10146.5210988281,
3506.75934082032, 13551.8667152343, 9222.76466718747, 5501.55972480469,
13922.8457027344, 4250.15196503907, 9017.17755468752, 3575.14872451172,
5562.49420546876, 17743.048228125, 24449.2857210939, 5704.12143984373,
15124.9334800781, 5079.61518925782, 10921.1189097656, 35210.8651640626,
4445.87090449217, 15901.6300136718, 11364.1122761719, 9222.57776601566,
8388.0708205078, 9823.76574609376, 6197.90128417968, 8764.95285703127,
9621.21499453124, 6218.11219218749, 15561.3999234375, 4677.02849882812,
3778.64337919922, 2264.6449546875, 2498.85718242187)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -96L)), structure(list(
`First Scan` = c(16668, 16732, 16751, 16894, 16948, 16970,
17120, 17177, 17210, 17367, 17403, 17406, 17633, 17638, 17833,
17917, 18052, 18090, 18149, 18285, 18338, 18376, 18397, 18504,
18561, 18605, 18642, 18662, 18702, 18753, 18755, 18792, 18932,
18983, 19022, 19210, 19238, 19249, 19438, 19586, 19669, 19707,
19742, 19898, 19937, 20040, 20131, 20172, 20302, 20361, 20405,
20613, 20633, 20790, 20962, 21004, 21148, 21187, 21382, 21454,
21455, 21585, 21726, 21729, 21966, 22000, 22197, 22267, 22585,
22789, 23382, 23725), TMT126 = c(1882.9047259105, 3449.99254746093,
1024.2977771073, 5158.15467082831, 15759.4817531249, 5163.23808916981,
23084.5250109376, 11158.1465572494, 2542.16341682018, 6236.75949960936,
2540.56668486328, 4643.57579941405, 3676.30715654298, 2933.73809824218,
0, 3710.6456292118, 4085.0294783203, 675.688557714844, 1950.23111088867,
2205.57922470703, 8296.83276855471, 2672.59435136718, 3034.29849873047,
45624.8063390625, 22890.978928125, 3676.17324550782, 804.357999226392,
2339.07756328126, 2307.76013144531, 21624.511528125, 1518.1371897772,
10635.9306925781, 2680.27191738282, 11041.5375597656, 7065.95542382811,
8761.31611523439, 1801.56362783203, 7668.99884179686, 7505.24644894218,
1129.2046734375, 5552.81345566407, 6607.18650630685, 2071.91356259765,
5463.23402109373, 5149.03205670459, 1219.86494693985, 4910.47049139314,
3155.11395608923, 1398.27528804432, 6326.38970151936, 3541.72186757812,
4198.17516679688, 1440.07868518477, 0, 3465.05218769531,
961.89374368008, 2280.46133583984, 2356.01639560548, 0, 2526.26822314453,
1853.50988980811, 1310.57137792969, 1419.80935503652, 1688.71382270508,
1531.11097573243, 1821.7144977539, 1352.28257709961, 2137.31568546879,
1951.55034804646, 1311.16770682422, 0, 1720.31448781044),
TMT127N = c(2771.68523671875, 5795.16860742187, 1532.51465844727,
4997.19921035158, 25241.5731433593, 7411.63585078126, 35598.7388882813,
11632.0612353516, 3981.85727929688, 8431.46010673831, 4482.49877431641,
6676.69583173827, 4001.42575561522, 3282.20197690431, 1573.56998100586,
3935.30607905274, 7116.32664960937, 2307.64589311523, 4102.16486528321,
4772.48413124998, 14428.697888086, 3332.28787353515, 5485.6754455078,
91312.7273437499, 37781.7556101563, 4225.51941313476, 1839.82785454101,
4019.30935473634, 3973.05389443358, 32996.0530066406, 2037.37071027832,
20023.8569953125, 3530.19987890626, 16245.3700406251, 11744.1997277344,
14524.1289123047, 2272.03076718749, 7951.62546621093, 11169.627975,
2088.36168669433, 8426.40678837892, 5546.88783515623, 825.817551295166,
11964.5538246094, 5850.03650859376, 1951.7206411377, 6372.5401716797,
2720.9217121582, 2928.83477036133, 7842.02046181641, 4470.19431181639,
5518.54197597655, 4886.56620761718, 2598.45832382813, 5150.38777236328,
1764.69598916016, 4431.15874072266, 5851.29773701172, 3535.65924873047,
4506.44162783202, 3948.30497885742, 3474.47286108398, 4899.0403397461,
3668.68391484374, 1715.68195283204, 1517.17190141602, 2988.61810048828,
3049.25398110351, 3346.69140673828, 1629.18274760742, 1652.68488032226,
3111.11825932616), TMT128C = c(3546.93682792969, 5443.04733562549,
2406.94690743869, 7409.37070198117, 24566.1728096405, 7605.80923058386,
37319.8058793624, 13554.5726592211, 4322.44607961136, 10647.2819212435,
5886.92810075651, 8753.17848761496, 6553.53110235196, 4646.29586668501,
1968.9492260545, 4154.15849160926, 7670.78133562564, 2768.92031395084,
3603.54312466775, 4079.51357784559, 16511.9767178725, 3885.32503013637,
4789.39730709742, 75477.2031668271, 39696.3689381062, 6235.92097131154,
2324.05125227432, 4163.9149784173, 5315.6094992347, 31155.5901563382,
1816.81292346028, 16308.3860112984, 4287.50902664535, 15935.5273428347,
12014.8172808907, 13939.1329255981, 3921.1247165634, 11449.7683673977,
13003.5107817882, 2150.04455439802, 10889.4027696227, 6249.74721525204,
3815.90910915446, 9774.84044695728, 5968.13675351661, 3450.75965045113,
6496.88961226217, 4185.18567482653, 3493.2378779832, 6249.25306422371,
4966.6136218745, 7318.69851904571, 4807.8110810617, 1540.76095735796,
6832.23484476677, 2965.60747444571, 4139.87531020355, 4987.87787026309,
3610.04293593895, 5899.23647575952, 5796.31857744029, 3008.6643611543,
5433.73871616973, 2796.2558469155, 2533.88330506493, 3404.51135442734,
1989.89578135028, 3963.71640004554, 1855.68417729492, 1858.78970920819,
1801.24628626465, 1521.81316450196), TMT129N = c(5603.3715375,
7466.48746787111, 5737.87805507811, 10125.7479275391, 27223.0979882812,
11989.9738019531, 44015.6930296875, 17091.8407880859, 7938.03088417966,
12459.8042378906, 7051.86322177736, 10014.4530556641, 7992.80055556639,
5937.58603710939, 3499.28743828124, 8939.26554726561, 11082.9714445312,
3852.90205781249, 4749.96272050781, 6339.30068320313, 18824.0227183594,
5960.32649501952, 4809.15115634765, 84223.8693140624, 36909.3952734375,
7050.83312226562, 2210.35349326172, 5805.73487548829, 6812.68262490236,
29434.3397519532, 2379.38804296874, 20404.2909726562, 5217.36262587891,
19563.0384855469, 13420.0282283203, 12340.821178125, 3700.34673647461,
10695.0951164062, 15392.6850773437, 2774.59824887696, 12177.5412128907,
7713.37043554689, 3815.38668457032, 11456.5398427734, 11993.45544375,
3913.54135283203, 9596.82833613281, 5349.46382695312, 3289.20360688477,
8314.06658349611, 5784.25196894531, 7882.8373013672, 5610.97252675783,
3071.51274536133, 7498.057575293, 3661.76029086913, 6717.39973330079,
6506.75830341797, 4466.70268945312, 5969.45083388673, 7538.86863662107,
3945.00036079102, 7081.96355947265, 3515.28444770509, 4725.6043602539,
4937.22756269533, 3392.35801362304, 5545.30827919922, 4755.80240244142,
3465.95602353517, 2446.60899624023, 3763.70442260743), TMT130C = c(10983.9436123188,
9211.23508829853, 10557.3906937124, 10405.446046875, 28290.6707273437,
16687.4414721715, 47013.3588375, 24663.9287051498, 10819.8059091653,
12112.6441605469, 12221.0968142757, 14143.6632554762, 8870.24921835937,
10222.1638647599, 4387.39878905819, 7903.13580132335, 12659.3879214159,
4977.95176757538, 6713.09197134976, 8619.08616316083, 25601.7183693629,
9371.93738344518, 8431.95007587771, 96391.5124218752, 44929.6342171874,
7378.82902968752, 3945.11645284669, 8071.18750848737, 7751.84701707912,
38104.5129609375, 3638.03642401144, 20403.32641875, 7808.49545553976,
23539.4361984374, 18752.01165285, 20811.394168736, 5824.4538993184,
18893.4697542139, 12674.1161636719, 2807.67847851562, 12264.333778125,
11014.4240599255, 6251.73090996096, 13488.8996818318, 15964.1844357857,
5828.08199702709, 11239.0816570313, 8253.48396721728, 4132.48828007812,
13706.3856985815, 7642.39674902346, 8508.96873105467, 8428.07027860162,
5015.03055391062, 9927.36947998573, 4157.77188427735, 6591.46973203123,
10252.0377530773, 5571.05266915471, 8466.28209717723, 9830.67984953953,
6387.25448143305, 8227.90628531475, 6429.95347392001, 5927.99930589914,
6179.43049557376, 4779.11406556715, 5853.8402419922, 5984.37583438957,
2653.83845332031, 4653.86852737383, 4421.67880346553), TMT131 = c(13383.1659585937,
10027.0432195313, 16206.8438039063, 16355.4699128906, 29514.0965624999,
32393.8092585938, 53039.4243328127, 23782.9527632812, 21228.6799054688,
15934.2437460937, 11102.0789214844, 15037.0606933593, 13194.4500703125,
9207.67683515628, 6735.74908359374, 12899.2203527343, 13469.5999195312,
6745.45593691405, 7115.74944609379, 11411.3147414063, 27412.2978679687,
11739.3367394532, 8886.12224414064, 96689.4600375001, 45453.11203125,
7980.59650781252, 6961.24482539061, 10250.2241015625, 13306.6513335937,
39924.4417171876, 6483.56406328127, 22704.3346148437, 9771.777984375,
24691.8792656249, 18723.0097054687, 16477.3002410156, 7680.46611621096,
17120.4574535157, 18478.2819375, 4914.95838925784, 14805.4535964844,
11972.9694691407, 6757.70631679689, 12590.9775105469, 19122.4749375,
7233.17976562498, 14106.4787144532, 11431.40191875, 7873.65249257815,
16542.6268992187, 8767.54336992188, 11536.5155554687, 10534.8182027344,
6824.66757714841, 13787.927071875, 7553.96639121096, 7917.68129238283,
12813.6645140625, 7735.42080351564, 7866.51996796874, 12833.8237371094,
7160.45798144533, 11867.8380820313, 7840.4843214844, 6481.4439357422,
8916.9703347656, 7413.33213457034, 12091.0962304687, 10392.2846542969,
5704.91811914064, 5982.57808242186, 6364.45633183592)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -72L))), `# of PSMs` = c(96,
72)), row.names = c(NA, -2L), groups = structure(list(Unipro.ID = c("Q13177",
"Q8TD19"), Gene.name = c("PAK2", "NEK9"), Mod.site = c("Q13177_278",
"Q8TD19_81"), Mod.site2 = c("PAK2_278", "NEK9_81"), `mod.or.not(Y/N)` = c("Y",
"Y"), `kinase.or.not(Y/N)` = c("Y", "Y"), .rows = structure(list(
1L, 2L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = c(NA, -2L), class = c("tbl_df", "tbl",
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"))
Here is the final data frame that I want (of course, the NA would be replaced by the sum values).
Besides this, how to call pivot_longer for 6 TMT columns in all nested tables?
Does anyone know how to do that? Thanks for any help!
df %>%
mutate(data = map(data, ~summarise(.x, across(where(is.numeric), sum)))) %>%
unnest_wider(data) %>%
select(-`First Scan`) %>%
ungroup()
# A tibble: 2 x 13
Unipro.ID Gene.name Mod.site Mod.site2 `mod.or.not(Y/N)` `kinase.or.not(Y/N)` TMT126
<chr> <chr> <chr> <chr> <chr> <chr> <dbl>
1 Q13177 PAK2 Q13177_278 PAK2_278 Y Y 1.00e5
2 Q8TD19 NEK9 Q8TD19_81 NEK9_81 Y Y 3.56e5
# ... with 6 more variables: TMT127N <dbl>, TMT128C <dbl>, TMT129N <dbl>,
# TMT130C <dbl>, TMT131 <dbl>, # of PSMs <dbl>
You can do summarise(across(starts_with("TMT"), sum)) after calling unnest(data):
df <- structure(list(Unipro.ID = c("Q13177", "Q8TD19"), Gene.name = c(
"PAK2",
"NEK9"
), Mod.site = c("Q13177_278", "Q8TD19_81"), Mod.site2 = c(
"PAK2_278",
"NEK9_81"
), `mod.or.not(Y/N)` = c("Y", "Y"), `kinase.or.not(Y/N)` = c(
"Y",
"Y"
), data = list(structure(list(`First Scan` = c(
18638, 18640,
18699, 18889, 18890, 19117, 19277, 19387, 19395, 19495, 19502,
19576, 19650, 19726, 19802, 19879, 19956, 20034, 20111, 20189,
20266, 20342, 20420, 20497, 20574, 20670, 20727, 20803, 20918,
20956, 21033, 21147, 21185, 21263, 21377, 21416, 21492, 21607,
21646, 21762, 21840, 21879, 21994, 22072, 22113, 22240, 22298,
22356, 22473, 22530, 22703, 22760, 22820, 22936, 23012, 23165,
23243, 23281, 23396, 23472, 23572, 23590, 23665, 23741, 23760,
23894, 23970, 23990, 24122, 24200, 24372, 24428, 24568, 24605,
24661, 24702, 24860, 25051, 25116, 25457, 25459, 25470, 25522,
25806, 26042, 26288, 26516, 27123, 27344, 27573, 27867, 28024,
28224, 29830, 30443, 32854
), TMT126 = c(
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 683.603289421257, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1058.63721546934, 5105.06075558397, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 786.877999584963, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1158.61443528477, 0, 0, 0, 0, 0, 790.552967308115,
1769.24251582031, 0, 0, 4230.5333458008, 0, 754.027149866911,
0, 0, 937.667214973757, 0, 0, 16065.4787548108, 0, 1033.79325384522,
0, 1545.17012178734, 22490.6473715619, 0, 12391.863457809, 1694.80635977683,
1669.92554702357, 2915.19207246094, 1305.76068893333, 1218.70367092158,
1724.48555844726, 1220.71902820389, 1142.29342043404, 15089.1510828024,
786.642299340822, 0, 0, 803.014098225646
), TMT127N = c(
0, 0,
0, 0, 0, 0, 0, 865.592199462889, 0, 0, 959.490090490725, 0, 0,
0, 3632.481907304, 0, 0, 0, 0, 0, 2281.36683418381, 0, 0, 1148.88409380685,
2282.96815473633, 0, 737.964767776176, 0, 0, 714.336386722035,
1336.78857436523, 0, 992.266982382272, 0, 8167.51299697265, 1481.83583737793,
0, 0, 0, 0, 0, 994.583403515622, 0, 3822.09582135578, 730.363546764861,
0, 0, 1601.84151123047, 0, 0, 0, 0, 1248.0926793457, 0, 2349.57136347657,
0, 925.784469760195, 0, 0, 0, 0, 0, 0, 0, 2869.82125708008, 779.87640303955,
0, 4092.33059296876, 0, 0, 0, 1133.40195924235, 0, 0, 0, 15684.5063332031,
0, 0, 0, 2583.52765913085, 24540.0170683595, 1238.62926386719,
11428.895775, 1483.56418256835, 1332.67443391114, 1825.25018671875,
1123.61925747071, 1030.31205838623, 1533.51140185547, 2153.17955595703,
1008.89100509033, 12831.9995203125, 1684.62781442872, 0, 1136.51165412598,
0
), TMT128C = c(
1611.91088437501, 1786.68805515069, 0, 1823.53765170799,
874.032758349609, 0, 0, 1177.50190689896, 646.466474431654, 1499.41582602539,
1255.4240426748, 1783.93500465848, 5996.15327152243, 8208.12153691405,
21348.7184882813, 33456.1981237878, 46046.4520991817, 5945.01241588586,
6798.69927773436, 18048.0166453125, 3490.51877753905, 7744.45986702618,
11529.8069519532, 3396.17701757812, 4651.27894687501, 14325.2306858641,
1561.40410561524, 0, 9592.47815625001, 2089.33504892578, 3367.76334082031,
10669.6799841273, 1439.18170268554, 0, 9310.75753007808, 1700.90959455201,
0, 6206.48464218753, 3397.72012818408, 0, 7079.64974935495, 1845.17109756826,
1177.34360229492, 6097.26335625001, 1754.74566738282, 1392.17984296875,
7026.71143068691, 2193.1615467585, 2836.98221749547, 6301.54294276034,
0, 3623.93436796874, 1312.70517940113, 0, 4724.16524276671, 0,
3946.52595689374, 2970.83282951206, 865.842519287108, 3283.01703994418,
0, 0, 1262.2417984723, 3482.3909258789, 4262.98461721732, 725.868942626953,
3139.75638657914, 6559.00482506506, 719.443235961914, 1980.26911301631,
735.412520327744, 2538.58699423828, 0, 0, 3345.73545624628, 17476.7195602775,
0, 3061.52193035407, 0, 3370.09478829905, 23476.7103351433, 1087.0128899699,
11912.6099077086, 1957.73038989257, 3158.21345361328, 3399.21823401529,
2593.01804501953, 934.40066220703, 2667.04373535038, 2390.35165488282,
1286.71902949219, 13590.0106023424, 1817.04336728435, 720.287557226125,
916.984646430313, 0
), TMT129N = c(
5236.22537109374, 5253.53062265625,
2574.52071173515, 6331.35667763673, 2909.4254578125, 2260.77584003907,
2299.19597588428, 2146.42980395508, 1524.82949099121, 4594.55742216798,
2945.06894956055, 3353.94465205077, 17265.8083640626, 58543.518953906,
42651.7719375001, 85288.5246984373, 147283.5420375, 16268.584838086,
31273.8547945313, 64984.9260843748, 15376.6111124999, 18807.9172359374,
41234.0440359375, 7038.37527421877, 14994.4310613281, 35007.7380726561,
5527.67209306639, 8827.66559818178, 32485.2518203124, 6771.8957270508,
10744.4285308594, 21706.4754328126, 7351.69939775389, 7286.74206159669,
31413.8810906249, 5402.31355253905, 7530.87224590352, 22346.2738640626,
7845.50157832029, 8598.84479102795, 13646.5870857421, 3948.41240126953,
4709.55193242188, 14502.506803125, 5527.37162548826, 4609.58657929687,
17346.4145701172, 3806.28572124023, 6695.23604707033, 10312.3288382812,
5030.34046109047, 12238.5130183594, 4008.11956391603, 3366.81581267473,
10163.4030287109, 5657.196356792, 9102.44150449222, 3997.46163222657,
3410.17096083986, 7459.02988359372, 2817.01574699993, 3228.9395395409,
1668.4944914795, 8344.1621935547, 6186.76663623048, 4037.21344028321,
4953.59359042969, 6163.53660527345, 2403.32564355468, 7143.26629951174,
1674.84291965332, 6149.94359912111, 2371.20030146484, 2708.46439392749,
8739.23083300782, 17708.4475347656, 2940.52380873895, 6755.28018515623,
2318.903026372, 5194.7135689453, 37003.6496414061, 1967.3172459961,
11835.060703125, 6357.79309687501, 6929.07336386721, 4922.18842499999,
5119.39548720702, 5098.90275791014, 5251.26713525389, 3925.45210825196,
3679.82248959962, 14610.4555587891, 3124.13869614258, 1892.91264873047,
2424.18607792969, 1217.02803508301
), TMT130C = c(
8534.51942065459,
7915.5220132809, 5427.32003829632, 6570.76122664215, 4059.66840776324,
6061.80182135341, 4680.93892861494, 3924.40329255471, 1651.02954082353,
9963.97493859979, 2095.70639501953, 6791.52962729408, 29089.1005494669,
84188.5986999335, 79102.1477485965, 111076.559352845, 228355.265937366,
31033.9549731673, 34443.9266034838, 100401.13011289, 20754.0266423186,
29334.7579023722, 70572.5366141732, 12419.2333360566, 17842.2049581652,
61518.6150214895, 10110.7438562966, 17502.4708992952, 61357.4708251869,
9995.86560411634, 17530.0854369149, 53203.79872126, 11560.0754183956,
13608.3534926174, 46828.7269257867, 11019.0036476036, 12751.4728461078,
26876.5493340097, 15817.3356058367, 13322.0303678209, 28346.2564980389,
6207.28749858749, 9509.23448457102, 36589.1961503305, 10263.6194964664,
7564.4130620443, 29223.5021208951, 7015.27604618795, 8985.64276558643,
18886.2813530505, 7104.5605795249, 17804.4468985063, 6812.45760606556,
6606.50436956103, 18488.5028791766, 5863.36827860186, 13255.0296116594,
6453.52502342659, 5515.76995189115, 13991.8058338637, 3809.92839574631,
5061.53991882257, 5991.94758913396, 11334.5748098943, 6206.71330898436,
5219.26272399663, 10963.7722168793, 7489.68230742191, 3361.11015884112,
9301.91002246388, 2802.03791217282, 10320.7319848397, 2509.93049810913,
3062.67670544402, 12115.818468418, 22596.7672476562, 5210.67744771832,
12678.5528095273, 3674.33047767757, 10158.3722420368, 38620.8279703125,
4299.66130273203, 16002.3112734375, 9597.19786319193, 10816.7672483378,
10449.5441895035, 8882.17509875803, 5726.84640941102, 8043.21098886215,
7002.83669129089, 4997.59224291582, 17214.8268832032, 4203.51644882184,
2044.40880964859, 2570.59274774035, 1621.14734118819
), TMT131 = c(
9418.17036445313,
8878.68274218749, 8378.77222617187, 5645.64330000002, 4753.99889121092,
4420.32600410157, 5180.99550117188, 4787.09710488281, 4537.51669335937,
11573.2264957031, 3011.21359365234, 6855.67281093751, 33135.919678125,
78639.2005781249, 89222.1922968751, 117395.8545375, 221719.7701125,
31420.3548656251, 46548.5491968752, 99822.2995687501, 21221.19759375,
31903.8316523437, 65884.2084140624, 12792.6073300781, 32494.3474710937,
55493.9358187499, 10832.2051148437, 16887.821878125, 56011.2740859373,
11016.5575394531, 15928.4518980469, 45726.2466890625, 10025.5855992188,
21737.7840796876, 59706.8427656249, 9716.2620714844, 18071.6204882813,
35495.48536875, 19939.4042976562, 13032.988340625, 32501.3787140625,
7199.69156542971, 10150.1181632812, 40466.1293437499, 10645.1514984375,
11109.5601890625, 28522.8374835938, 5834.91936972658, 6796.13434628906,
23190.480225, 9266.24059453124, 29075.5950890626, 7621.3969927734,
9322.90506210938, 22800.4644656249, 7069.82396484372, 15978.9590683593,
6530.85736874999, 6011.4814611328, 17323.3141382813, 4554.70168183593,
5415.33720234375, 6123.79340332032, 14385.484575, 10146.5210988281,
3506.75934082032, 13551.8667152343, 9222.76466718747, 5501.55972480469,
13922.8457027344, 4250.15196503907, 9017.17755468752, 3575.14872451172,
5562.49420546876, 17743.048228125, 24449.2857210939, 5704.12143984373,
15124.9334800781, 5079.61518925782, 10921.1189097656, 35210.8651640626,
4445.87090449217, 15901.6300136718, 11364.1122761719, 9222.57776601566,
8388.0708205078, 9823.76574609376, 6197.90128417968, 8764.95285703127,
9621.21499453124, 6218.11219218749, 15561.3999234375, 4677.02849882812,
3778.64337919922, 2264.6449546875, 2498.85718242187
)), class = c(
"tbl_df",
"tbl", "data.frame"
), row.names = c(NA, -96L)), structure(list(
`First Scan` = c(
16668, 16732, 16751, 16894, 16948, 16970,
17120, 17177, 17210, 17367, 17403, 17406, 17633, 17638, 17833,
17917, 18052, 18090, 18149, 18285, 18338, 18376, 18397, 18504,
18561, 18605, 18642, 18662, 18702, 18753, 18755, 18792, 18932,
18983, 19022, 19210, 19238, 19249, 19438, 19586, 19669, 19707,
19742, 19898, 19937, 20040, 20131, 20172, 20302, 20361, 20405,
20613, 20633, 20790, 20962, 21004, 21148, 21187, 21382, 21454,
21455, 21585, 21726, 21729, 21966, 22000, 22197, 22267, 22585,
22789, 23382, 23725
), TMT126 = c(
1882.9047259105, 3449.99254746093,
1024.2977771073, 5158.15467082831, 15759.4817531249, 5163.23808916981,
23084.5250109376, 11158.1465572494, 2542.16341682018, 6236.75949960936,
2540.56668486328, 4643.57579941405, 3676.30715654298, 2933.73809824218,
0, 3710.6456292118, 4085.0294783203, 675.688557714844, 1950.23111088867,
2205.57922470703, 8296.83276855471, 2672.59435136718, 3034.29849873047,
45624.8063390625, 22890.978928125, 3676.17324550782, 804.357999226392,
2339.07756328126, 2307.76013144531, 21624.511528125, 1518.1371897772,
10635.9306925781, 2680.27191738282, 11041.5375597656, 7065.95542382811,
8761.31611523439, 1801.56362783203, 7668.99884179686, 7505.24644894218,
1129.2046734375, 5552.81345566407, 6607.18650630685, 2071.91356259765,
5463.23402109373, 5149.03205670459, 1219.86494693985, 4910.47049139314,
3155.11395608923, 1398.27528804432, 6326.38970151936, 3541.72186757812,
4198.17516679688, 1440.07868518477, 0, 3465.05218769531,
961.89374368008, 2280.46133583984, 2356.01639560548, 0, 2526.26822314453,
1853.50988980811, 1310.57137792969, 1419.80935503652, 1688.71382270508,
1531.11097573243, 1821.7144977539, 1352.28257709961, 2137.31568546879,
1951.55034804646, 1311.16770682422, 0, 1720.31448781044
),
TMT127N = c(
2771.68523671875, 5795.16860742187, 1532.51465844727,
4997.19921035158, 25241.5731433593, 7411.63585078126, 35598.7388882813,
11632.0612353516, 3981.85727929688, 8431.46010673831, 4482.49877431641,
6676.69583173827, 4001.42575561522, 3282.20197690431, 1573.56998100586,
3935.30607905274, 7116.32664960937, 2307.64589311523, 4102.16486528321,
4772.48413124998, 14428.697888086, 3332.28787353515, 5485.6754455078,
91312.7273437499, 37781.7556101563, 4225.51941313476, 1839.82785454101,
4019.30935473634, 3973.05389443358, 32996.0530066406, 2037.37071027832,
20023.8569953125, 3530.19987890626, 16245.3700406251, 11744.1997277344,
14524.1289123047, 2272.03076718749, 7951.62546621093, 11169.627975,
2088.36168669433, 8426.40678837892, 5546.88783515623, 825.817551295166,
11964.5538246094, 5850.03650859376, 1951.7206411377, 6372.5401716797,
2720.9217121582, 2928.83477036133, 7842.02046181641, 4470.19431181639,
5518.54197597655, 4886.56620761718, 2598.45832382813, 5150.38777236328,
1764.69598916016, 4431.15874072266, 5851.29773701172, 3535.65924873047,
4506.44162783202, 3948.30497885742, 3474.47286108398, 4899.0403397461,
3668.68391484374, 1715.68195283204, 1517.17190141602, 2988.61810048828,
3049.25398110351, 3346.69140673828, 1629.18274760742, 1652.68488032226,
3111.11825932616
), TMT128C = c(
3546.93682792969, 5443.04733562549,
2406.94690743869, 7409.37070198117, 24566.1728096405, 7605.80923058386,
37319.8058793624, 13554.5726592211, 4322.44607961136, 10647.2819212435,
5886.92810075651, 8753.17848761496, 6553.53110235196, 4646.29586668501,
1968.9492260545, 4154.15849160926, 7670.78133562564, 2768.92031395084,
3603.54312466775, 4079.51357784559, 16511.9767178725, 3885.32503013637,
4789.39730709742, 75477.2031668271, 39696.3689381062, 6235.92097131154,
2324.05125227432, 4163.9149784173, 5315.6094992347, 31155.5901563382,
1816.81292346028, 16308.3860112984, 4287.50902664535, 15935.5273428347,
12014.8172808907, 13939.1329255981, 3921.1247165634, 11449.7683673977,
13003.5107817882, 2150.04455439802, 10889.4027696227, 6249.74721525204,
3815.90910915446, 9774.84044695728, 5968.13675351661, 3450.75965045113,
6496.88961226217, 4185.18567482653, 3493.2378779832, 6249.25306422371,
4966.6136218745, 7318.69851904571, 4807.8110810617, 1540.76095735796,
6832.23484476677, 2965.60747444571, 4139.87531020355, 4987.87787026309,
3610.04293593895, 5899.23647575952, 5796.31857744029, 3008.6643611543,
5433.73871616973, 2796.2558469155, 2533.88330506493, 3404.51135442734,
1989.89578135028, 3963.71640004554, 1855.68417729492, 1858.78970920819,
1801.24628626465, 1521.81316450196
), TMT129N = c(
5603.3715375,
7466.48746787111, 5737.87805507811, 10125.7479275391, 27223.0979882812,
11989.9738019531, 44015.6930296875, 17091.8407880859, 7938.03088417966,
12459.8042378906, 7051.86322177736, 10014.4530556641, 7992.80055556639,
5937.58603710939, 3499.28743828124, 8939.26554726561, 11082.9714445312,
3852.90205781249, 4749.96272050781, 6339.30068320313, 18824.0227183594,
5960.32649501952, 4809.15115634765, 84223.8693140624, 36909.3952734375,
7050.83312226562, 2210.35349326172, 5805.73487548829, 6812.68262490236,
29434.3397519532, 2379.38804296874, 20404.2909726562, 5217.36262587891,
19563.0384855469, 13420.0282283203, 12340.821178125, 3700.34673647461,
10695.0951164062, 15392.6850773437, 2774.59824887696, 12177.5412128907,
7713.37043554689, 3815.38668457032, 11456.5398427734, 11993.45544375,
3913.54135283203, 9596.82833613281, 5349.46382695312, 3289.20360688477,
8314.06658349611, 5784.25196894531, 7882.8373013672, 5610.97252675783,
3071.51274536133, 7498.057575293, 3661.76029086913, 6717.39973330079,
6506.75830341797, 4466.70268945312, 5969.45083388673, 7538.86863662107,
3945.00036079102, 7081.96355947265, 3515.28444770509, 4725.6043602539,
4937.22756269533, 3392.35801362304, 5545.30827919922, 4755.80240244142,
3465.95602353517, 2446.60899624023, 3763.70442260743
), TMT130C = c(
10983.9436123188,
9211.23508829853, 10557.3906937124, 10405.446046875, 28290.6707273437,
16687.4414721715, 47013.3588375, 24663.9287051498, 10819.8059091653,
12112.6441605469, 12221.0968142757, 14143.6632554762, 8870.24921835937,
10222.1638647599, 4387.39878905819, 7903.13580132335, 12659.3879214159,
4977.95176757538, 6713.09197134976, 8619.08616316083, 25601.7183693629,
9371.93738344518, 8431.95007587771, 96391.5124218752, 44929.6342171874,
7378.82902968752, 3945.11645284669, 8071.18750848737, 7751.84701707912,
38104.5129609375, 3638.03642401144, 20403.32641875, 7808.49545553976,
23539.4361984374, 18752.01165285, 20811.394168736, 5824.4538993184,
18893.4697542139, 12674.1161636719, 2807.67847851562, 12264.333778125,
11014.4240599255, 6251.73090996096, 13488.8996818318, 15964.1844357857,
5828.08199702709, 11239.0816570313, 8253.48396721728, 4132.48828007812,
13706.3856985815, 7642.39674902346, 8508.96873105467, 8428.07027860162,
5015.03055391062, 9927.36947998573, 4157.77188427735, 6591.46973203123,
10252.0377530773, 5571.05266915471, 8466.28209717723, 9830.67984953953,
6387.25448143305, 8227.90628531475, 6429.95347392001, 5927.99930589914,
6179.43049557376, 4779.11406556715, 5853.8402419922, 5984.37583438957,
2653.83845332031, 4653.86852737383, 4421.67880346553
), TMT131 = c(
13383.1659585937,
10027.0432195313, 16206.8438039063, 16355.4699128906, 29514.0965624999,
32393.8092585938, 53039.4243328127, 23782.9527632812, 21228.6799054688,
15934.2437460937, 11102.0789214844, 15037.0606933593, 13194.4500703125,
9207.67683515628, 6735.74908359374, 12899.2203527343, 13469.5999195312,
6745.45593691405, 7115.74944609379, 11411.3147414063, 27412.2978679687,
11739.3367394532, 8886.12224414064, 96689.4600375001, 45453.11203125,
7980.59650781252, 6961.24482539061, 10250.2241015625, 13306.6513335937,
39924.4417171876, 6483.56406328127, 22704.3346148437, 9771.777984375,
24691.8792656249, 18723.0097054687, 16477.3002410156, 7680.46611621096,
17120.4574535157, 18478.2819375, 4914.95838925784, 14805.4535964844,
11972.9694691407, 6757.70631679689, 12590.9775105469, 19122.4749375,
7233.17976562498, 14106.4787144532, 11431.40191875, 7873.65249257815,
16542.6268992187, 8767.54336992188, 11536.5155554687, 10534.8182027344,
6824.66757714841, 13787.927071875, 7553.96639121096, 7917.68129238283,
12813.6645140625, 7735.42080351564, 7866.51996796874, 12833.8237371094,
7160.45798144533, 11867.8380820313, 7840.4843214844, 6481.4439357422,
8916.9703347656, 7413.33213457034, 12091.0962304687, 10392.2846542969,
5704.91811914064, 5982.57808242186, 6364.45633183592
)
), class = c(
"tbl_df",
"tbl", "data.frame"
), row.names = c(NA, -72L))), `# of PSMs` = c(
96,
72
)), row.names = c(NA, -2L), groups = structure(list(Unipro.ID = c(
"Q13177",
"Q8TD19"
), Gene.name = c("PAK2", "NEK9"), Mod.site = c(
"Q13177_278",
"Q8TD19_81"
), Mod.site2 = c("PAK2_278", "NEK9_81"), `mod.or.not(Y/N)` = c(
"Y",
"Y"
), `kinase.or.not(Y/N)` = c("Y", "Y"), .rows = structure(list(
1L, 2L
), ptype = integer(0), class = c(
"vctrs_list_of", "vctrs_vctr",
"list"
))), row.names = c(NA, -2L), class = c(
"tbl_df", "tbl",
"data.frame"
), .drop = TRUE), class = c(
"grouped_df", "tbl_df",
"tbl", "data.frame"
))
library(tidyverse)
df %>%
unnest(data) %>%
summarise(across(starts_with("TMT"), sum)) %>%
pivot_longer(starts_with("TMT")) %>%
# select only a few columns for optimized printing
select(Unipro.ID, Gene.name, Mod.site, Mod.site2, name, value)
#> `summarise()` has grouped output by 'Unipro.ID', 'Gene.name', 'Mod.site', 'Mod.site2', 'mod.or.not(Y/N)'. You can override using the `.groups` argument.
#> Adding missing grouping variables: `mod.or.not(Y/N)`
#> # A tibble: 12 × 7
#> # Groups: Unipro.ID, Gene.name, Mod.site, Mod.site2, mod.or.not(Y/N) [2]
#> `mod.or.not(Y/N)` Unipro.ID Gene.name Mod.site Mod.site2 name value
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
#> 1 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT126 100372.
#> 2 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT127N 127769.
#> 3 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT128C 435779.
#> 4 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT129N 1189693.
#> 5 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT130C 1869744.
#> 6 Y Q13177 PAK2 Q13177_278 PAK2_278 TMT131 2008380.
#> 7 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT126 355683.
#> 8 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT127N 572770.
#> 9 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT128C 594897.
#> 10 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT129N 716943.
#> 11 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT130C 904627.
#> 12 Y Q8TD19 NEK9 Q8TD19_81 NEK9_81 TMT131 1075259.
Created on 2021-09-19 by the reprex package (v2.0.1)
I am working on a project analyzing natural disasters effect on interest rates. I am trying to control for countries that use the euro. I want to match a vector that describes the countries that use the euro and create a column that has a dummy variable for each country: 1 if they use the euro and 0 if not.
Country EURO
ARG 0
FRA 1
GBR 0
CHN 0
I've tried to set the euro category to a Boolean variable, but I have not had any success. I am relatively new to R so I am not confident I am coding it right.
I have created the euro column with this code:
exchangerates$euro <- exchangerates$Country
I have set aside a vector that lists the countries that use the euro:
euro_countries <- c("AUT", "BEL", "CYP", "EST", "FIN",
"FRA", "DEU", "GRC", "IRL", "ITA",
"EU28", "LVA", "LTU", "LUX", "MLT",
"NLD", "PRT", "SVK", "SVN")
All help is appreciated. I just want to make a dummy category using factor levels.
Here is a picture of my data in a table. The euro column just has the countries listed when I want the euro_countries vector to be matched with the countries and a 1 placed where the matched countries are
This is the output when I use the dput function:
6.625, 6.625, 6.625, 6.625, 6.646758, 8.57, 8.57, 8.57, 41.094167,
75.804733, 91.579292, 122.432417, 134.506333, 142.171667,
157.066667, 179.729167, 207.689167, 257.229167, 285.684695,
308.186667, 328.870833, 359.817527, 398.662222, 437.935,
477.786741, 516.61739, 526.235513, 573.287957, 525.829201,
505.66424, 502.901462, 499.766833, 534.56577, 544.739367,
567.51309, 0.610215, 0.711918, 0.711918, 0.899819, 0.793523,
0.773006, 0.79674, 0.884758, 1.063449, 0.884104, 0.800652,
0.728078, 27.144917, 31.698417, 32.281167, 38.598417, 32.738518,
28.209, 23.957417, 22.595583, 20.293667, 17.071667, 19.063,
19.09825, 19.5775, 19.570583, 23.376333, 21.729917, 0.826111,
0.84851, 0.798459, 0.84533, 0.829721, 0.732749, 0.769379,
0.886609, 0.899704, 0.938627, 1.11751, 1.062552, 0.886034,
0.805365, 0.80412, 0.797141, 0.730638, 0.682675, 0.719843,
0.755045, 0.719355, 0.778294, 0.753159, 0.753731, 0.904035,
0.887397, 0.847186, 6.045025, 5.635942, 7.123367, 9.144992,
10.596392, 6.188558, 6.036133, 6.97624, 7.894714, 5.99691,
5.443701, 5.624075, 5.616312, 0.238301, 0.234094, 0.248228,
0.360607, 0.417515, 0.386279, 0.35015, 0.460783, 0.403429,
0.430937, 0.554865, 0.660267, 0.862031, 0.966193, 1.021986,
0.74212, 0.711464, 0.612635, 0.624521, 0.805104, 0.749396,
0.761251, 0.879964, 0.897884, 0.938627, 1.085401, 1.11751,
1.062552, 0.886034, 0.805365, 0.80412, 0.797141, 0.730638,
0.719843, 0.755045, 0.719355, 0.778294, 0.753159, 0.753731,
0.901659, 0.904035, 0.887397, 0.847186, 0.804251, 0.79669,
0.778294, 0.847186, 0.643067, 0.80412, 0.639863, 0.75265,
0.75265, 0.79185, 0.846731, 0.732194, 0.747789, 0.688018,
0.648582, 0.644185, 0.828501, 1.00191, 1.161858, 1.332267,
1.369789, 1.055876, 0.916327, 0.90813, 0.972646, 0.830127,
0.860135, 0.807037, 0.863354, 0.846404, 0.760947, 0.779856,
0.889798, 0.899375, 0.938627, 1.085401, 1.11751, 1.062552,
0.886034, 0.805365, 0.80412, 0.797141, 0.730638, 0.682675,
0.719843, 0.755045, 0.719355, 0.778294, 0.753159, 0.753731,
0.901659, 0.904035, 0.887397, 0.847186, 0.357143, 0.357143,
0.416667, 0.40039, 0.55651, 0.573272, 0.497641, 0.659725,
0.751807, 0.779246, 0.682197, 0.611927, 0.611173, 0.563177,
0.567015, 0.666757, 0.653427, 0.633668, 0.640958, 0.610836,
0.603824, 0.618057, 0.660931, 0.694655, 0.667223, 0.612472,
0.54618, 0.549998, 0.499772, 0.543966, 0.641919, 0.647179,
0.633047, 0.639661, 0.60773, 0.654545, 0.777003, 0.749582,
0.0773, 0.088042, 0.088042, 0.088041, 0.088041, 0.088041,
0.088041, 0.088041, 0.10811, 0.107837, 0.108697, 0.125067,
0.162607, 0.258442, 0.33079, 0.405338, 0.410803, 0.397445,
0.416318, 0.465191, 0.534898, 0.67278, 0.711967, 0.679861,
0.706417, 0.801344, 0.86729, 0.896982, 1.072336, 1.11751,
1.062552, 0.886034, 0.805365, 0.797141, 0.730638, 0.682675,
0.719843, 0.755045, 0.778294, 0.753731, 0.901659, 0.904035,
0.887397, 0.847186, 5.434161, 6.160583, 8.277666, 8.341541,
6.704969, 5.949237, 5.837793, 5.364536, 5.498011, 5.850292,
5.748165, 6.858304, 6.623831, 6.279025, 60, 48.042208, 45.83215,
78.988392, 152.646667, 186.789167, 237.145833, 282.179167,
286.49, 257.886667, 224.306667, 202.745833, 199.5825, 210.39,
183.625833, 172.113333, 207.944167, 225.104167, 223.695,
232.601667, 281.523333, 274.433333, 149.583333, 296.291667,
326, 362.833333, 415, 415, 415, 415, 415, 442.045417, 623.0555,
626.994, 631.756667, 661.42075, 909.264833, 1025.944833,
1110.58, 1282.56, 1643.848333, 1685.704167, 1770.059167,
1842.813333, 1950.3175, 2029.920833, 2087.103867, 2160.753675,
2248.607975, 2342.296292, 2909.38, 10013.6225, 7855.15, 8421.775,
10260.85, 9311.191667, 8577.133333, 8938.85, 9704.741667,
9159.316667, 9141, 9698.9625, 10389.9375, 9090.433333, 8770.433333,
9386.629167, 10461.24, 11865.2113, 13389.41294, 13308.3268,
13380.83388, 14236.93877, 4.7619, 4.7619, 4.7619, 4.7619,
4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619, 4.7619,
4.7619, 4.7619, 4.7619, 6.359125, 7.5, 7.5, 7.5, 7.5, 7.491935,
7.594468, 7.742039, 8.101603, 8.375892, 8.960413, 8.738576,
8.19284, 8.125791, 7.862945, 8.658523, 9.455132, 10.098898,
11.362583, 12.36875, 12.610833, 12.9615, 13.917083, 16.2255,
17.5035, 22.742433, 25.918083, 30.493292, 31.373742, 32.427077,
35.433173, 36.313286, 41.259365, 43.055428, 44.941605, 47.186414,
48.610319, 46.583284, 45.316467, 44.099975, 45.307008, 41.348533,
43.505183, 48.405267, 45.725812, 46.670467, 53.437233, 58.597845,
61.029514, 64.151944, 67.195313, 65.121569, 68.39784, 1.02173,
0.943578, 0.854428, 0.767669, 0.788885, 0.859929, 0.793622,
0.8917, 0.938627, 1.085401, 1.062552, 0.886034, 0.805365,
0.80412, 0.719843, 0.719355, 0.753731, 0.901659, 0.887397,
0.847186, 0.901342, 0.999517, 1.821717, 24.842767, 31.693742,
43.013983, 64.691667, 66.5, 78.615947, 122.241811, 0.00035,
0.056214, 2.279108, 2.459083, 3.011292, 3.44935, 3.800075,
4
9.342342, 9.655958, 10.789019, 11.285967, 10.897892, 10.899242,
10.928192, 11.129717, 13.513475, 12.636008, 12.423325, 13.169458,
12.771992, 13.29245, 15.848267, 18.664058, 18.926517, 19.244342,
37.881758, 65.903867, 68.037133, 64.349792, 54.322258, 49.409933,
49.283683, 48.801767, 44.729817, 47.89025, 46.395342, 46.437131,
55.537075, 55.731725, 54.665458, 1.724365, 1.456408, 1.199768,
1.456037, 1.507186, 1.111773, 0.826307, 0.797957, 0.842808,
0.825878, 0.728624, 0.885448, 0.900179, 0.938627, 1.062552,
0.886034, 0.80412, 0.797141, 0.730638, 0.682675, 0.755045,
0.778294, 0.753159, 0.904035, 0.847186, 6.259742, 6.214501,
7.094129, 6.335157, 8.801842, 8.991654, 6.4425, 5.64, 5.604607,
0.714288, 0.892857, 1.004889, 1.030312, 0.964425, 0.978502,
1.02668, 1.152795, 1.496773, 1.763992, 2.023372, 1.913161,
1.694561, 1.526401, 1.672148, 1.733514, 1.861792, 1.686522,
1.523877, 1.454848, 1.512421, 1.868249, 1.889614, 2.201149,
2.378751, 2.162191, 1.722099, 1.508681, 1.420273, 1.542056,
1.360675, 1.387834, 1.265811, 1.234284, 1.219408, 1.433975,
1.436525, 1.407408, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1e-06, 2e-06, 3e-06, 1.1e-05, 1.4e-05,
1.7e-05, 0.000129, 0.002666, 0.187886, 0.7725, 1.245833,
1.988319, 2.195, 2.253333, 2.453333, 2.664167, 2.93, 3.383333,
3.49, 3.506833, 3.5165, 3.478467, 3.413175, 3.295842, 3.274033,
3.128045, 2.924408, 3.011508, 2.825125, 2.7541, 2.637586,
2.701899, 2.839044, 3.184439, 3.375062, 3.260488, 0.000332,
0.004422, 0.008482, 0.009155, 0.026508, 0.95, 1.362643, 2.272277,
3.279292, 3.4754, 3.967108, 4.346075, 4.0939, 4.080033, 3.657642,
3.235483, 3.103158, 2.76795, 2.409242, 3.120142, 3.0153,
2.962848, 3.256542, 3.160617, 3.154542, 3.7695, 3.942783,
3.779333, 3.611717, 0.143404, 0.143404, 0.122281, 0.244029,
0.306992, 0.552567, 0.849925, 0.746136, 0.785398, 0.720673,
0.769364, 0.874455, 1.085401, 1.11751, 1.062552, 0.886034,
0.805365, 0.80412, 0.797141, 0.682675, 0.719843, 0.755045,
0.753159, 0.753731, 0.901659, 0.904035, 0.887397, 0.847186,
6e-04, 0.002, 0.002, 0.001718, 0.002128, 0.002243, 0.007639,
0.076005, 0.165509, 0.203328, 0.308422, 0.716794, 0.887558,
1.533284, 2.170872, 2.906079, 3.305543, 3.320007, 3.263657,
2.913653, 2.808983, 2.43825, 2.518858, 3.049325, 3.1779,
3.4682, 3.327917, 3.349175, 4.005667, 4.059183, 4.052492,
3.941617, 0.991667, 2.19075, 4.55915, 5.120833, 5.784833,
9.705083, 24.6199, 28.129167, 29.168525, 31.348483, 30.692025,
28.813742, 28.284442, 27.190958, 25.580845, 24.852875, 30.367915,
29.382341, 30.839831, 31.837144, 38.378207, 60.93765, 67.055933,
58.342801, 62.668133, 4.5, 3.428171, 3.622136, 3.75, 3.75,
3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75, 3.75,
3.75, 3.75, 1.115852, 1.169535, 1.372995, 1.528088, 1.605086,
1.504572, 1.220637, 1.070733, 1.029617, 0.985768, 0.819702,
0.755045, 0.778294, 0.753159, 0.887397, 0.693266, 0.86427,
0.802792, 0.804146, 0.730638, 0.778294, 0.753731, 4.355892,
4.481642, 8.603925, 5.91879, 8.262428, 9.737123, 8.086304,
7.473088, 6.513972, 8.692518, 2.8, 2.8, 2.8, 2.8, 0.233336,
9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 9e-06, 1.1e-05,
1.5e-05, 1.4e-05, 1.4e-05, 1.4e-05, 1.6e-05, 1.8e-05, 2.4e-05,
7.6e-05, 0.000111, 0.000225, 0.000367, 0.000522, 0.000675,
0.000857, 0.001422, 0.002609, 0.004172, 0.006872, 0.010985,
0.029609, 0.045845, 0.081405, 0.260724, 0.418783, 0.625219,
1.225588, 1.507226, 1.500885, 1.425537, 1.343583, 1.428453,
1.302931, 1.301522, 1.54996, 1.502849, 1.674955, 1.796001,
1.903768, 2.188542, 2.720009, 3.648133, 0.714286, 0.714286,
0.714286, 0.714286, 0.714286, 0.679477, 0.869565, 0.869565,
0.778834, 0.877579, 1.085816, 1.1141, 1.475277, 2.285032,
2.036033, 2.273468, 2.587321, 2.761315, 3.267742, 3.550798,
3.627085, 4.299349, 4.607962, 5.528284, 6.109484, 6.939828,
8.609181, 10.540747, 7.564749, 6.459693, 6.359328, 6.771549,
7.045365, 8.261223, 8.473674, 7.321222, 7.261132, 8.209969,
9.655056, 10.852656, 12.758931, 14.709611, 13.333781), diff = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1e-06, 6e-06, 5.3e-05,
3.4e-05, 0.00012, 0.000661, 0.445255, 0.465965, 0.037088,
0.00830399999999998, 6.20000000000065e-05, 0.00074200000000002,
-0.000162999999999913, 0, 0, 0, 0, 2.063757, -0.162628, 0.022672,
-0.0196429999999999, 0.150655, 0.0413359999999998, 0.0485160000000002,
0.565942, 0.186188, 0.213845000000001, 0.426793999999999,
0.922419000000001, 2.615923, 1.15791, 5.524989, 1.804532,
11.532285, 0, 0, 0, 0, -0.0101870000000001, -0.134584, -0.00744800000000001,
0.067205, 0.054413, 0.083541, -0.028166, 0.0209820000000001,
-0.016397, -0.00802900000000006, 0.115648, 0.124152, 0.029504,
0.292376, 0.064079, -0.148272, -0.0153110000000001, 0.0164599999999999,
0.00269900000000001, 0.0778920000000001, 0.108912, -0.102809,
-0.018718, -0.07117, 0.0695170000000001, 0.244448, -0.0418780000000001,
0.174877, 0.208616, -0.0928800000000001, -0.298649, -0.182162,
-0.050279, 0.0185, -0.1329, -0.00289500000000009, 0.0900110000000001,
-0.19203, -0.120696, -0.00366199999999994, 0.070042, 0.07352,
0.221727, 0.0141239999999998, -0.0404559999999998, 0.0336539999999999,
0, 0.115259, -0.0927119999999999, 0.038001, -0.031213, 0.217207,
0.0822959999999999, 0.0657020000000001, 0.148671, 0.0494479999999999,
-0.135232, 0.022244, 0.046718, -0.015288, -0.097405, 0.036704,
0.117562, 0.0127050000000001, 0.039005, 0.146774, -0.0549580000000001,
-0.176518, -0.00124500000000005, -0.00697899999999996, -0.066503,
-0.047963, 0.037168, 0.0589390000000001, -0.025135, 0.00237600000000004,
-0.016638, 0, 0, 0, 0, 0, -0.023377, -0.124998, 0.045271,
0.21223, 0.134881, 0.164905, 0.0395160000000001, -0.1819,
-0.148391, -0.0495479999999999, 0.0606599999999999, -0.02826,
-0.0985740000000001, 0.0130079999999999, 0.038807, -0.0549580000000001,
-0.176518, -0.00124500000000005, -0.00697899999999996, -0.066503,
-0.047963, 0.037168, 0.035202, -0.03569, 0.0589390000000001,
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004,
-0.040211, 0, -9.00000000000001e-05, 0.00135, 0.004253, 1.50399,
0.0784790000000002, 0.076025, 0.286892, 0.0614330000000001,
-0.107733, -0.000976000000000088, -0.014866, -0.130217, -0.0919329999999998,
0.0707, 0.115592, 0.00061599999999995, 0.290217, -0.078416,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1e-06, 2.9e-05, 0.000146, 0.001777,
0.626407, 0.252983, 0.0874330000000001, 0.072892, 0.082525,
0.653416, 0.01549, 0.520209, 0.570731, 0.157112, -0.152356,
-0.490729, -0.259063, -0.228269, -0.113291, 0.165661, -0.240201,
-0.0863980000000002, 0.28024, 0.20302, 0.196863, 0.973952,
0.164409, -0.299924, 0.462436, 0, 0.004, -0.01, 0.013, -0.011491,
0.043284, 0.0557000000000001, -0.000625000000000098, -0.000665999999999833,
-0.03186, -0.035123, -0.02205, 0.039125, -0.031133, 0.077425,
0.0307499999999998, -0.00220799999999999, 0.0296910000000001,
0.0348249999999999, -0.00131599999999987, 0.0626499999999999,
0.070416, 0.024017, -0.0635079999999999, -0.0952840000000001,
-0.046716, -0.017217, -0.0210579999999998, 0.063008, 0.0813489999999999,
0.075564, 0.00680300000000011, -0.00897300000000012, 0.0211490000000001,
0.098846, 0.00226900000000008, -0.000622000000000122, 0.0636510000000001,
0.0205569999999999, -0.168266, -0.100033, -0.089256, -0.0773999999999999,
-0.0602640000000001, -0.00705899999999993, 0.0760609999999999,
-0.112938, -0.0406319999999999, 0.00965699999999992, 0.0306090000000001,
0.0763079999999998, 0.172993, 0.0463019999999998, -0.027663,
-0.00198199999999993, 0, 0, 0, 0, -0.397967, -0.0816409999999999,
-0.096117, 0.066033, 0.068867, 0.250541, 0.107442, -0.658208,
-0.307725, -0.027892, -0.246767, 0.071399, -0.109924, 0.215303,
-0.00150000000000006, 0.0523419999999999, 0.186688, -0.00122800000000001,
-0.129008, -0.211956, 0.00168100000000004, 0.00866600000000006,
-0.053477, 0.00505199999999983, -0.0452359999999998, -0.154864,
0.049642, -0.01078, -0.0107529999999999, -0.00070199999999998,
-0.00680900000000007, 9e-06, 0.000184, 0.000105, 0.000564,
0.000685, 0.00085, 0.000694, 0.001808, 0.000931, 0.521184,
8.481666, 10.12, 5.59, 11.908333, 27.88, 19.689167, 62.3825,
32.07, 26.476667, 25.605, 21.9425, 37.949166, 44.3125, 13.36,
41.59, -23.403334, 7.02833300000003, 48.489167, 30.810833,
95.350833, 53.9983340000001, 2.46083299999998, -81.868333,
-49.761667, -29.4925000000001, -7.810833, -0.00313099999993938,
-50.6107280000001, -26.581667, 2.80380299999996, 8.80157500000001,
75.075338, 83.7758680000001, 22.8336519999999, -28.1239429999999,
0, 0, 0, 0, 0, 0, 0, -0.0283090000000001, -0.101284, 0.0815919999999999,
-0.174234, -0.12865, -0.0565530000000001, 0.206156, 0.188,
0.0831330000000001, 0.344367, 0.616616, 0.516134, 0.269308,
0, 0.0430079999999999, 1.0181, 0.540184, 0.1912, 0.247366,
2.856785, -0.267326000000001, -0.0372419999999991, -0.0243580000000012,
-0.010859, -0.000707999999999487, 0.000253999999999976, -0.00143599999999999,
-0.000109999999999388, 7.89999999994961e-05, -0.000235999999999237,
-0.0824840000000009, -0.220879, -0.365906, -0.658877, -0.117239,
-0.0611470000000001, -0.308808, -0.149128, -0.116575, -0.0523239999999996,
0.0840550000000002, 0.416989, 0.114277, -0.142798, 0, 0,
0, 0.201207999999999, 1.475, 1.006392, 1.784275, 1.029475,
1.122958, 1.488833, 1.933709, 1.771341, 2.427142, 3.764983,
2.080942, 3.455133, 4.730533, 7.210242, 9.594167, 14.769583,
21.962942, 41.494425, 51.94975, 48.346083, 56.566333, 83.39425,
119.691167, 130.785917, 126.236833, 103.782683, -18.228793,
67.990525, 123.860002, 104.276525, 285.074516, 330.19339,
331.672994, 211.729314, 204.608175, 373.411127, -249.039555,
-307.778726, 40.3052299999999, -282.84757, -110.580528, 190.544594,
-259.686267, -50.4301659999999, -51.2435580000001, 71.8894150000001,
132.995721, 740.099807, 312.240818, -102.794271, 4.37656800000013,
0, 0, 0, 0, 0.0117580000000004, 0.640000000000001, 0, 0,
3.6875, 13.028533, 10.075084, 30.853125, 12.073916, 7.665334,
14.895, 22.6625, 27.96, 24.631667, 28.455528, 22.501972,
20.684166, 30.946694, 38.844695, 39.272778, 39.851741, 5.31557199999997,
9.61812299999997, 47.052444, -47.458756, -20.164961, -2.76277800000003,
-3.13462899999996, -3.75142999999991, 10.173597, 22.773723,
0, 0, 0, 0.087574, 0.0108469999999999, -0.067952, 0.023734,
0.00671200000000005, 0.135768, -0.159271, -0.083452, -0.056026,
0.60425, 4.5535, 0.582750000000004, 4.029167, -5.29681, -4.529518,
-1.742333, -1.361834, -2.301916, -3.222, 1.991333, 0.0352500000000013,
1.881583, -0.00691700000000139, -1.063584, -1.646416, -0.135139,
0.0223989999999999, -0.050051, 0.046871, -0.015609, -0.0969720000000001,
0.0366300000000001, 0.11723, 0.013095, 0.038923, 0.0321089999999999,
-0.0549580000000001, -0.176518, -0.080669, -0.00124500000000005,
-0.00697899999999996, -0.066503, -0.047963, 0.037168, 0.035202,
-0.03569, 0.0589390000000001, -0.025135, 0.000572000000000017,
0.00237600000000004, -0.016638, -0.040211, 0.298875, 0.374984,
1.487425, 0.81255, 0.239800000000001, -1.121617, -0.360325,
0.275412999999999, -0.428103000000001, 0.00585300000000011,
-0.503077, 0.263208000000001, -0.176164, 0, 0, 0.014134,
0, -0.003193, -0.031236, -0.036129, 0.004243, -0.057354,
0.027508, 0.123928, 0.105402, 0.201764, 0.104162, 0.0557930000000001,
-0.099588, 0.011364, -0.0988289999999999, 0.011886, 0.0402530000000001,
-0.0557080000000001, 0.0118550000000001, 0.118713, 0.01792,
0.040743, 0.146774, 0.0321089999999999, -0.0549580000000001,
-0.176518, -0.080669, -0.00124500000000005, -0.00697899999999996,
-0.066503, 0.037168, 0.035202, -0.03569, 0.0589390000000001,
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004,
-0.016638, -0.040211, -0.000751999999999975, -0.00756100000000004,
0.0589390000000001, -0.040211, -0.078664, -0.00124500000000005,
0.088545, 0, 0, 0.0392, 0.054881, 0.078523, 0.015595, -0.059771,
-0.039436, -0.00439699999999998, 0.184316, 0.173409, 0.159948,
0.170409, 0.0375219999999998, -0.313913, -0.139549, -0.00819700000000001,
0.064516, -0.142519, 0.030008, -0.053098, 0.056317, -0.0169499999999999,
-0.085457, 0.018909, 0.109942, 0.00957700000000006, 0.039252,
0.146774, 0.0321089999999999, -0.0549580000000001, -0.176518,
-0.080669, -0.00124500000000005, -0.00697899999999996, -0.066503,
-0.047963, 0.037168, 0.035202, -0.03569, 0.0589390000000001,
-0.025135, 0.000572000000000017, 0.147928, 0.00237600000000004,
-0.016638, -0.040211, 0, 0, 0.054564, -0.01053, 0.104469,
0.0167620000000001, 0.067346, 0.087278, 0.092082, 0.027439,
-0.0970489999999999, -0.0702700000000001, 0.049003, -0.0479959999999999,
0.00383800000000001, 0.096983, -0.0133300000000001, -0.019759,
0.00729000000000002, -0.030122, -0.00701200000000002, 0.0142329999999999,
0.0428740000000001, 0.033724, -0.027432, -0.054751, -0.066292,
0.00381799999999999, -0.0437150000000001, 0.044194, 0.0979530000000001,
0.00525999999999993, 0.00890600000000008, 0.00661400000000001,
-0.031931, 0.0468150000000001, 0.036369, -0.027421, 0.03328,
0.010742, 0, -1.000000000001e-06, 0, 0, 0, 0, 0.000941999999999998,
-0.000272999999999995, 0.00086, 0.01637, 0.03754, 0.062395,
0.072348, 0.074548, 0.005465, -0.013358, 0.018873, -0.011453,
0.069707, 0.113354, 0.039187, -0.032106, 0.0265559999999999,
0.094927, 0.0659460000000001, 0.0296919999999999, 0.175354,
0.045174, -0.0549580000000001, -0.176518, -0.080669, -0.00697899999999996,
-0.066503, -0.047963, 0.037168, 0.035202, 0.0589390000000001,
0.000572000000000017, 0.147928, 0.00237600000000004, -0.016638,
-0.040211, 0.203404999999999, 0.726422, 1.165923, 0.0638749999999995,
-1.166714, -0.0851040000000003, -0.111444000000001, -0.473256999999999,
0.214065, 0.506422, 0.043285, 1.110139, -0.182159, -0.344806,
0, 5.371058, -4.28725, 4.25300900000001, 26.965242, 34.1425,
22.744166, 45.033334, 4.310833, -28.603333, -33.58, -21.560834,
-3.16333299999999, 10.8075, -26.764167, -11.5125, 5.60249999999999,
24.049167, -1.409167, 8.906667, 2.190833, -7.08999999999997,
0, 146.708334, 29.708333, 36.833333, 23.125, 0, 0, 0, 0,
27.045417, 181.010083, 3.93849999999998, 4.76266699999996,
29.664083, 247.844083, 116.68, 84.6351669999999, 171.98,
361.288333, 41.8558340000002, 84.3549999999998, 72.7541660000002,
107.504167, 79.6033329999998, 57.1830339999999, 73.6498080000001,
87.8543, 93.6883170000001, 567.083708, 7104.2425, -2158.4725,
566.625, 1839.075, -949.658333000001, -734.058333999999,
361.716667000001, 765.891667, -545.425000000001, -18.3166669999991,
557.9625, 690.975, -1299.504167, -320, 616.195833999998,
1074.610833, 1403.9713, 1524.20164, -81.0861399999994, 72.5070799999994,
856.104890000001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1.597225, 1.140875, 0, 0, 0, -0.00806500000000021,
0.102533, 0.147571, 0.359564000000001, 0.274289, 0.584521000000001,
-0.221837000000001, -0.545736, -0.0670490000000008, -0.262846,
0.795578000000001, 0.796609, 0.643765999999999, 1.263685,
1.006167, 0.242082999999999, 0.350667, 0.955583000000001,
2.308417, 1.278, 5.238933, 3.17565, 4.575209, 0.88045, 1.053335,
3.006096, 0.880113000000001, 4.946079, 1.796063, 1.886177,
2.244809, 1.423905, -2.027035, -1.266817, -1.216492, 1.207033,
-3.958475, 2.15665, 4.900084, -2.679455, 0.944655000000004,
6.766766, 5.160612, 2.431669, 3.12243, 3.043369, -2.073744,
3.27627100000001, 0.127121, -0.257105, -0.0891500000000001,
-0.128186, 0.0212159999999999, 0.113677, 0.00164400000000009,
0.054126, 0.0469269999999999, 0.146774, -0.0549580000000001,
-0.176518, -0.080669, -0.00124500000000005, 0.037168, -0.03569,
)), row.names = c(NA, -1567L), class = "data.frame")
Simply use ifelse to conditionally assign with %in%:
euro_countries <- c("AUT", "BEL", "CYP", "EST", "FIN",
"FRA", "DEU", "GRC", "IRL", "ITA",
"EU28", "LVA", "LTU", "LUX", "MLT",
"NLD", "PRT", "SVK", "SVN")
exchangerates$euro <- ifelse(exchangerates$country %in% euro_countries, 1, 0)
Alternatively without ifelse
exchangerates$euro <- as.integer(exchangerates$country %in% euro_countries)
I have trained a simple model and I am now trying to backtest it using quantstrat. I am still getting to know how quantstrat works, so I know I am making some mistakes in the code. The model is very simple (54% test accuracy) but I am just applying it to quantstrat for education on the quantstrat package.
The data looks like:
open high low close volume adjusted direction returns
2018-11-23 1030.00 1037.590 1022.399 1023.88 691500 1023.88 1 -0.013232313
2018-11-26 1038.35 1049.310 1033.910 1048.62 1850400 1048.62 0 0.024162978
2018-11-27 1041.00 1057.580 1038.490 1044.41 1803200 1044.41 0 -0.004014763
2018-11-28 1048.76 1086.840 1035.760 1086.23 2475400 1086.23 0 0.040041693
2018-11-29 1076.08 1094.245 1076.000 1088.30 1468900 1088.30 0 0.001905737
2018-11-30 1089.07 1095.570 1077.880 1094.43 2580200 1094.43 0 0.005632642
sma rsi momentum roc pred
2018-11-23 1041.794 42.72473 -31.93005 -0.03910309 1
2018-11-26 1040.041 51.77642 -44.77002 -0.01219856 0
2018-11-27 1040.619 47.50633 -37.98999 0.02364954 0
2018-11-28 1045.637 48.46232 20.07996 0.05727916 0
2018-11-29 1050.101 51.31756 49.67004 0.04769691 0
2018-11-30 1053.073 56.61429 58.38000 0.06663439 0
Much of the information in the table is not of any use anymore. The strategy I am trying to apply is when the column pred = 0, long the position. When the column pred = 1, short the position and close each position at the end of each period. (In this case I have daily data, but the period could be hours, weeks, months etc.)
Questions:
Where am I going wrong in the add.signal and add.rule.
How can I add a rule to close out a position at the end of each period?
Code:
require(quantstrat)
require(PerformanceAnalytics)
library(e1071)
mean(test$pred == test$direction)
initDate="2007-01-01"
from <- "2017-07-09"
to <- "2018-12-01"
init_equity <- 1
adjustment <- TRUE
currency('USD')
Sys.setenv(TZ="UTC")
symbols <- 'GOOG'
GOOG <- test
currency('USD')
Sys.setenv(TZ="UTC")
stock("GOOG", currency="USD", multiplier=1)
symbols <- c("GOOG")
strategy.st <- portfolio.st <- account.st <- "SVMstrat"
rm.strat(strategy.st)
rm.strat(portfolio.st)
rm.strat(account.st)
initPortf(name = portfolio.st,
symbols = symbols,
initDate = initDate,
currency = 'USD')
initAcct(name = account.st,
portfolios = portfolio.st,
initDate = initDate,
currency = 'USD',
initEq = init_equity)
initOrders(portfolio.st,
symbols = symbols,
initDate = initDate)
strategy(strategy.st, store = TRUE)
########### Adding to the strategy
add.signal(strategy.st,
name = "sigThreshold",
arguments = list(column = "pred",
threshold = 0.5,
relationship = "gte",
cross = TRUE),
label = "longEntry")
add.signal(strategy.st,
name = "sigThreshold",
arguments = list(column = "pred",
threshold = 0.5,
relationship = "lte",
cross = TRUE),
label = "longExit")
applySignals(strategy = strategy.st, mktdata=GOOG)
###################################################
add.rule(strategy.st,
name="ruleSignal",
arguments=list(sigcol="longEntry",
sigval=TRUE,
orderqty = 100,
ordertype="market",
orderside="long",
replace=FALSE,
TxnFees = -10,
prefer="Open"),
type="enter",
path.dep=TRUE)
add.rule(strategy.st,
name="ruleSignal",
arguments=list(sigcol="longExit",
sigval=TRUE,
orderqty = 100,
ordertype="market",
orderside="long",
replace=FALSE,
TxnFees = -10,
prefer="Open"),
type="exit",
path.dep=TRUE)
applyStrategy(strategy=strategy.st,portfolios=portfolio.st)
updatePortf(portfolio.st)
dateRange <- time(getPortfolio(portfolio.st)$summary)[-1]
updateAcct(portfolio.st,dateRange)
updateEndEq(account.st)
chart.Posn(portfolio.st, 'GOOG')
Data:
test <- structure(c(1156.97998, 1144.589966, 1159.890015, 1185, 1189.390015,
1172.219971, 1196.560059, 1191, 1186.959961, 1181.01001, 1262.589966,
1239.130005, 1251, 1271, 1228.01001, 1220.01001, 1228, 1205.900024,
1229.619995, 1225, 1237, 1240.469971, 1249.900024, 1243, 1236.97998,
1235.189941, 1229.26001, 1224.72998, 1202.030029, 1205.02002,
1208, 1200, 1207.140015, 1208.819946, 1227.599976, 1241.290039,
1237.449951, 1244.22998, 1234.97998, 1204.27002, 1193.800049,
1186.300049, 1158.670044, 1172.189941, 1161.630005, 1172.719971,
1170.73999, 1179.099976, 1170.140015, 1157.089966, 1164.97998,
1179.98999, 1192, 1157.170044, 1176.150024, 1185.150024, 1186.72998,
1191.869995, 1199.890015, 1190.959961, 1205, 1195.329956, 1167.5,
1150.109985, 1146.150024, 1131.079956, 1072.939941, 1108, 1108.910034,
1104.589966, 1126.459961, 1121.839966, 1093.369995, 1103.060059,
1080.890015, 1104.25, 1071.790039, 1037.030029, 1082.469971,
1008.460022, 1059.810059, 1075.800049, 1073.72998, 1055, 1039.47998,
1069, 1091.380005, 1073.98999, 1061.390015, 1043.290039, 1050,
1044.709961, 1059.410034, 1057.199951, 1000, 1036.76001, 1030,
1038.349976, 1041, 1048.76001, 1076.079956, 1089.069946, 1159.589966,
1164.290039, 1184.410034, 1195.416992, 1191, 1203.040039, 1204.5,
1200, 1196.859985, 1206.48999, 1266, 1265.859985, 1269.770996,
1273.890015, 1234.916016, 1227.588013, 1233.469971, 1229.880005,
1230, 1226.088013, 1251.170044, 1256.5, 1255.541992, 1245.694946,
1249.272949, 1245.869995, 1235.23999, 1226, 1209.02002, 1211,
1217.26001, 1211.839966, 1221.280029, 1221.650024, 1243.089966,
1242.545044, 1250.660034, 1253.63501, 1238.660034, 1212.98999,
1199.01001, 1186.300049, 1175.26001, 1174.540039, 1178.680054,
1178.609985, 1178.609985, 1180.425049, 1177.23999, 1176.079956,
1173.209961, 1189.890015, 1192.209961, 1178, 1186.880005, 1194.22998,
1202.099976, 1195.410034, 1209.900024, 1209.959961, 1206.410034,
1197.51001, 1173.5, 1168, 1154.349976, 1132.170044, 1106.400024,
1115, 1113.446045, 1124.219971, 1128.98999, 1121.839966, 1110.359985,
1112.22998, 1107.890015, 1106.119995, 1110.97998, 1106.530029,
1097.040039, 1037.48999, 1091.939941, 1083.974976, 1082.974976,
1058.469971, 1064.344971, 1095.459961, 1093.27002, 1075.560059,
1062.119995, 1056.60498, 1054.563965, 1071.849976, 1067, 1060.790039,
1031.73999, 1048.560059, 1037.589966, 1049.310059, 1057.579956,
1086.839966, 1094.244995, 1095.569946, 1149.589966, 1141, 1155.935059,
1180, 1179.280029, 1170.599976, 1190.339966, 1183.319946, 1184.219971,
1181, 1235.560059, 1239.130005, 1249.02002, 1231, 1211.469971,
1205.599976, 1210.209961, 1204.790039, 1215.060059, 1215.796997,
1236.170044, 1238.008057, 1246.01001, 1232, 1233.640991, 1225.109985,
1209.51001, 1202.550049, 1188.23999, 1194.625977, 1200.354004,
1199, 1204.23999, 1206.359009, 1225.715942, 1228.689941, 1236.359009,
1232.589966, 1211.285034, 1192.5, 1162, 1152, 1157.214966, 1160.109985,
1156.23999, 1158.359985, 1162.849976, 1168.329956, 1154.030029,
1157.089966, 1154.579956, 1173.359985, 1166.040039, 1146.910034,
1168, 1174.765015, 1183.630005, 1184.5, 1190.300049, 1186.630005,
1193.829956, 1155.57605, 1145.119995, 1127.364014, 1137.572021,
1081.130005, 1068.27002, 1086.401978, 1089, 1102.5, 1102.189941,
1077.089966, 1087.75, 1091, 1070, 1048.73999, 1069.550049, 1034.089966,
995.830017, 1000.75, 1057, 1062.459961, 1054.609985, 1021.23999,
1038.069946, 1065.900024, 1072.204956, 1053.109985, 1031, 1031.150024,
1031, 1031.780029, 1048.97998, 1016.26001, 996.02002, 1033.469971,
1022.398987, 1033.910034, 1038.48999, 1035.76001, 1076, 1077.880005,
1152.839966, 1153.900024, 1183.47998, 1188.819946, 1183.859985,
1198.800049, 1195.880005, 1186.959961, 1184.910034, 1205.5, 1248.079956,
1263.699951, 1268.329956, 1238.5, 1219.73999, 1217.26001, 1220.01001,
1226.150024, 1223.709961, 1224.77002, 1242.219971, 1245.609985,
1249.099976, 1237.609985, 1235.01001, 1242.099976, 1214.380005,
1206.48999, 1200.959961, 1207.77002, 1201.619995, 1207.329956,
1205.380005, 1220.650024, 1241.819946, 1231.150024, 1249.300049,
1239.119995, 1218.189941, 1197, 1186.47998, 1171.439941, 1164.829956,
1164.640015, 1177.359985, 1162.819946, 1175.329956, 1172.530029,
1156.050049, 1161.219971, 1171.089966, 1186.869995, 1166.089966,
1173.369995, 1184.650024, 1180.48999, 1194.640015, 1193.469971,
1195.310059, 1200.109985, 1202.949951, 1168.189941, 1157.349976,
1148.969971, 1138.819946, 1081.219971, 1079.319946, 1110.079956,
1092.25, 1121.280029, 1115.689941, 1087.969971, 1096.459961,
1101.160034, 1103.689941, 1050.709961, 1095.569946, 1071.469971,
1020.080017, 1036.209961, 1076.77002, 1070, 1057.790039, 1040.089966,
1055.810059, 1093.390015, 1082.400024, 1066.150024, 1038.630005,
1036.050049, 1043.660034, 1064.709961, 1061.48999, 1020, 1025.76001,
1037.609985, 1023.880005, 1048.619995, 1044.410034, 1086.22998,
1088.300049, 1094.430054, 798400, 1120000, 1251900, 1221900,
1055700, 1610400, 1393600, 1276700, 1247400, 2619200, 3318200,
2127800, 2405600, 2130600, 1849900, 1644700, 1567200, 1531300,
1089600, 1081700, 1494000, 1370300, 841800, 1108700, 958100,
1348100, 1828800, 1343200, 1389600, 870800, 1205600, 887400,
992600, 946600, 1156300, 1304000, 1298900, 1331400, 1816400,
1831000, 2061300, 1888500, 1401300, 1115400, 1209300, 1295500,
1431200, 944000, 1306500, 1203600, 1191400, 1210000, 4405600,
1271000, 977700, 1462300, 1260800, 1380600, 1357600, 1687900,
1256200, 2209500, 1184300, 1932400, 1308700, 2675700, 2949000,
2101300, 1372400, 1928500, 1467200, 2094500, 1267600, 1514200,
1848700, 1982400, 2545800, 4187600, 3880700, 3212700, 2529800,
1482000, 1839000, 2441400, 1233300, 2058400, 1488200, 1343200,
1471800, 1513700, 1565900, 1836100, 1658100, 1858600, 2449100,
1534300, 691500, 1850400, 1803200, 2475400, 1468900, 2580200,
1152.839966, 1153.900024, 1183.47998, 1188.819946, 1183.859985,
1198.800049, 1195.880005, 1186.959961, 1184.910034, 1205.5, 1248.079956,
1263.699951, 1268.329956, 1238.5, 1219.73999, 1217.26001, 1220.01001,
1226.150024, 1223.709961, 1224.77002, 1242.219971, 1245.609985,
1249.099976, 1237.609985, 1235.01001, 1242.099976, 1214.380005,
1206.48999, 1200.959961, 1207.77002, 1201.619995, 1207.329956,
1205.380005, 1220.650024, 1241.819946, 1231.150024, 1249.300049,
1239.119995, 1218.189941, 1197, 1186.47998, 1171.439941, 1164.829956,
1164.640015, 1177.359985, 1162.819946, 1175.329956, 1172.530029,
1156.050049, 1161.219971, 1171.089966, 1186.869995, 1166.089966,
1173.369995, 1184.650024, 1180.48999, 1194.640015, 1193.469971,
1195.310059, 1200.109985, 1202.949951, 1168.189941, 1157.349976,
1148.969971, 1138.819946, 1081.219971, 1079.319946, 1110.079956,
1092.25, 1121.280029, 1115.689941, 1087.969971, 1096.459961,
1101.160034, 1103.689941, 1050.709961, 1095.569946, 1071.469971,
1020.080017, 1036.209961, 1076.77002, 1070, 1057.790039, 1040.089966,
1055.810059, 1093.390015, 1082.400024, 1066.150024, 1038.630005,
1036.050049, 1043.660034, 1064.709961, 1061.48999, 1020, 1025.76001,
1037.609985, 1023.880005, 1048.619995, 1044.410034, 1086.22998,
1088.300049, 1094.430054, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0,
0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1,
0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0,
0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0,
1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0,
1, 0, 0, 0, 0, 0, -0.00104855331105314, 0.000919518780805317,
0.0256347650444282, 0.00451208815547521, -0.00417217175459472,
0.012619789662035, -0.00243580570624413, -0.00745897913060267,
-0.00172703972109811, 0.0173768179939304, 0.03532140688511, 0.0125152198181764,
0.00366384836553646, -0.0235190818121779, -0.0151473637464675,
-0.0020332038141998, 0.00225917222073213, 0.00503275706729656,
-0.00199001994229053, 0.000866266545001881, 0.0142475327735407,
0.00272899653776371, 0.0028018328706636, -0.00919861598011906,
-0.00210080318639327, 0.00574081662706516, -0.0223170207999425,
-0.00649715490004299, -0.00458356807419513, 0.00567051294060583,
-0.0050920497264868, 0.00475188580729302, -0.00161509369523183,
0.0126682199278725, 0.0173431545355052, -0.00859216509959326,
0.0147423341154074, -0.00814860609999057, -0.0168910630806179,
-0.017394611699556, -0.0087886549707602, -0.0126761843887159,
-0.00564261535624044, -0.000163063285779752, 0.0109218040219923,
-0.0123496969365746, 0.0107583379894998, -0.00238224762817163,
-0.0140550600772716, 0.00447205724741084, 0.00849967727604639,
0.0134746513574004, -0.0175082604561083, 0.00624311091962526,
0.00961336070298957, -0.00351161432973557, 0.0119865692380838,
-0.000979411358491888, 0.00154179664734944, 0.00401563256651238,
0.00236642144094823, -0.0288956410622938, -0.00927928294838842,
-0.00724068360804975, -0.00883402112865139, -0.050578649594534,
-0.00175729735942876, 0.0284994362552065, -0.0160618664481138,
0.026578190890364, -0.00498545221124236, -0.0248455856607925,
0.00780351501080179, 0.0042865888105148, 0.00229749257318224,
-0.0480025938734183, 0.0426949269209413, -0.0219976598372297,
-0.0479621038301595, 0.0158124301340961, 0.0391427032421665,
-0.00628734072666692, -0.0114111785046729, -0.016733068328695,
0.0151141665758556, 0.0355934816870314, -0.0100512999471647,
-0.0150129338873702, -0.0258125201711763, -0.00248399910225972,
0.00734519052177562, 0.0201693332256125, -0.00302427056940058,
-0.0390865579429535, 0.00564706862745101, 0.0115523854356538,
-0.0132323129099419, 0.024162977965372, -0.00401476323174632,
0.0400416930502221, 0.00190573730988342, 0.00563264240007388,
1125.3989991, 1128.9430054, 1136.8930054, 1144.3530029, 1151.173999,
1158.3080078, 1167.6070068, 1173.8760009, 1178.3499999, 1183.494995,
1193.018994, 1203.9989867, 1212.4839843, 1217.4519897, 1221.0399902,
1222.8859863, 1225.2989868, 1229.2179931, 1233.0979858, 1235.0249878,
1234.4389893, 1232.6299927, 1230.7069947, 1230.6179932, 1232.1449952,
1234.6289918, 1234.0659913, 1232.0999879, 1229.8249879, 1228.1249879,
1224.0649903, 1220.2369874, 1215.8649903, 1214.1689942, 1214.8499878,
1213.7549926, 1217.246997, 1220.5099975, 1222.2329955, 1221.1559935,
1219.641992, 1216.0529905, 1211.9979856, 1206.3969847, 1199.9509886,
1193.1179808, 1185.7209715, 1179.0619749, 1172.8479857, 1169.2699828,
1167.7309814, 1169.2739868, 1169.3999878, 1170.2729858, 1171.0019897,
1172.7689941, 1174.7, 1176.7939942, 1180.7199952, 1184.6089966,
1187.7949951, 1185.9269897, 1185.0529907, 1182.6129883, 1178.0299805,
1168.1029786, 1156.5709717, 1148.2319702, 1137.9259643, 1130.0429687,
1121.3169677, 1113.2949707, 1107.2059692, 1102.4249755, 1098.911975,
1095.860974, 1097.485974, 1093.6249755, 1086.4079772, 1077.9009704,
1074.0089783, 1072.2119812, 1068.344989, 1062.2379822, 1057.449994,
1061.7179994, 1060.4010072, 1059.8690125, 1061.7240113, 1061.7080201,
1058.3970215, 1057.8680176, 1058.2380127, 1056.2290161, 1053.2240112,
1047.6460082, 1041.7940063, 1040.0410034, 1040.6190063, 1045.6369994,
1050.1010009, 1053.0730102, 45.4718259236287, 45.2372613787558,
56.9881807801438, 58.8717301068573, 68.2039283244873, 73.5215112680329,
78.8594307629251, 73.0335410836162, 71.845824268758, 73.323376014074,
89.1748677280385, 88.8275948061702, 88.079358554904, 72.9197089804835,
66.5774741060939, 65.5905607795046, 60.3560855296636, 60.5351059532554,
61.4085229097936, 58.076745639994, 63.2173375817626, 67.2733875032827,
68.7459719049055, 59.9037653356146, 44.6491666372171, 40.4929666577831,
30.2655738215587, 36.0522832244009, 40.7505784647263, 45.517250253278,
41.5835266382263, 41.3526668380199, 41.539756712543, 48.3189167794286,
49.8415866657383, 44.5858982397584, 50.0675010891207, 50.5139938354098,
44.9097955003298, 37.4247186375495, 41.3952548987526, 39.6467050713014,
39.3953595896288, 36.8289128008105, 42.8772642627352, 37.5760511024063,
42.0791664435174, 36.4236440580649, 25.1434697637668, 29.0666072154372,
25.3668839063101, 34.1040319281821, 34.1351918720353, 42.138526061446,
49.3942545777117, 53.2282422165058, 60.0907410718325, 59.6946479180297,
56.5126081396889, 64.5584522103826, 61.6638469740838, 48.5567687748239,
50.4491176695018, 45.8595330253583, 39.1134283844586, 22.2017732449298,
24.6509068125481, 33.7409449463083, 27.0354908046699, 36.9033514343542,
31.849732552439, 28.384694400023, 30.2843907497844, 30.2566110685775,
30.1702095862, 28.1229085893699, 39.7891005017724, 37.8236546439287,
33.4844836408483, 42.9231744072258, 49.6425369989148, 43.9761986844232,
44.7318583977582, 37.1424843378588, 40.8120228103859, 50.807226927847,
47.9214803669887, 44.995279725301, 41.3197867616665, 47.7401787161256,
40.9599257198947, 48.8101085201251, 58.7773921954413, 46.8976151314924,
38.7370234461344, 43.0052200556536, 42.7247275761847, 51.7764243779359,
47.5063348907638, 48.4623219235214, 51.3175593621287, 56.6142900584089,
-4.82006799999999, -1.57995600000004, 58.6699210000002, 70.3599850000001,
79.880005, 84.580078, 80.229981, 59.5, 82.020019, 81.2299800000001,
107.909912, 109.649902, 115.48999, 84.599976, 36.26001, 28.4400639999999,
36.1500249999999, 27.3499750000001, 27.829956, 37.8100589999999,
57.309937, 40.1099850000001, 1.02001999999993, -26.089966, -33.3199460000001,
3.59997599999997, -5.35998500000005, -10.7700199999999, -19.0500489999999,
-18.3800040000001, -22.089966, -17.4400639999999, -36.839966,
-24.959961, -7.2800299999999, -6.45996100000002, 14.290039, -2.97998099999995,
3.80993600000011, -9.48999000000003, -14.479981, -36.3300789999998,
-36.790039, -42.6899410000001, -28.0200199999999, -57.830078,
-66.48999, -58.619995, -93.25, -77.900024, -47.0999750000001,
-10.130005, -20.3900140000001, 1.93005399999993, 19.820068, 15.8499750000001,
17.2800299999999, 30.6500249999999, 19.9801029999999, 27.579956,
46.8999020000001, 6.9699700000001, -13.73999, -37.900024, -27.2700199999999,
-92.150024, -105.330078, -70.410034, -102.390015, -72.189942,
-79.6201179999998, -112.140014, -106.48999, -67.0299070000001,
-53.6600349999999, -98.26001, -43.25, -9.75, -59.2399290000001,
-73.869995, -15.4799800000001, -51.280029, -57.8999020000001,
-47.880005, -40.6499020000001, -7.77001900000005, -21.2899170000001,
15.440063, -56.9399410000001, -35.419922, 23.580017, 28.5, -15.2800299999999,
-50, -32.030029, -2.47998099999995, -31.9300539999999, -44.7700199999999,
-37.98999, 20.079956, 49.670044, 58.380005, 0.0222611532791754,
0.0452135091331929, 0.0513252799641881, 0.0417837604179434, 0.025502736394083,
0.039092663599452, 0.0357347902099496, 0.00293614990186253, -0.00329432207453095,
0.0181141450822189, 0.0402852378681278, 0.0551615667800078, 0.0663056560265511,
0.0442341189174087, 0.0117432944413327, -0.025003895701337, -0.0351848233779339,
-0.0338218411236912, -0.0120137739039121, 0.00411537451562882,
0.0202976386336982, 0.0207662940930682, 0.0185440740696787, 0.0112948922357141,
0.00832598771420034, -9.66018891714882e-05, -0.0253916951198745,
-0.0347079634534282, -0.0300608837885816, -0.0223033747170538,
-0.0331328340436947, -0.00582238916306288, -0.00092043524789176,
0.0162623189210285, 0.0278023013942841, 0.0242780692234357, 0.0341721602379419,
0.0276065721476719, -0.00201742129018712, -0.0367595754116454,
-0.0369577878306506, -0.0643497227781094, -0.0618263303728748,
-0.0449540628540124, -0.0165437954424839, -0.0201428806167474,
0.00331521089287889, 0.0065887162483893, -0.00740297497164288,
-0.0138034795252402, 0.00708686703803085, 0.0097706638268491,
-0.00550758934150863, 0.0148708818967105, 0.0199762409613848,
0.0079946880333539, 0.00652531170373116, 0.0232087632715174,
0.0185256691345472, 0.012965814191138, 0.0188472345861976, -0.0223894054190623,
-0.0307321178168358, -0.0395397517017582, -0.0524206155642792,
-0.106686826243081, -0.0791243287288781, -0.041700843048468,
-0.0506260747757752, -0.0155216754472765, 0.0313829883191348,
0.00798238469401547, -0.0123452722292345, 0.00812441164353306,
-0.0158118578835529, -0.0600069056977848, 0.00696117861714018,
-0.0230552625927682, -0.0764831282344325, -0.0630892695041085,
0.0244997487533043, -0.0236160780123607, -0.0128496474489905,
0.0194261429225948, 0.0187385123731847, 0.0153171376045522, 0.0115221715735752,
0.00787218840953852, -0.00140467331860261, -0.0188928482186341,
-0.0465491768740778, -0.0164783950656826, -0.0043804792361124,
-0.0180999145663217, -0.00998164151028913, -0.00581382135522279,
-0.0391030878479981, -0.0121985628088801, 0.0236495379306092,
0.0572791560421972, 0.0476969136015821, 0.0666343919981838, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0), .Dim = c(102L,
13L), .Dimnames = list(NULL, c("open", "high", "low", "close",
"volume", "adjusted", "direction", "returns", "sma", "rsi", "momentum",
"roc", "pred")), index = structure(c(1531180800, 1531267200,
1531353600, 1531440000, 1531699200, 1531785600, 1531872000, 1531958400,
1532044800, 1532304000, 1532390400, 1532476800, 1532563200, 1532649600,
1532908800, 1532995200, 1533081600, 1533168000, 1533254400, 1533513600,
1533600000, 1533686400, 1533772800, 1533859200, 1534118400, 1534204800,
1534291200, 1534377600, 1534464000, 1534723200, 1534809600, 1534896000,
1534982400, 1535068800, 1535328000, 1535414400, 1535500800, 1535587200,
1535673600, 1536019200, 1536105600, 1536192000, 1536278400, 1536537600,
1536624000, 1536710400, 1536796800, 1536883200, 1537142400, 1537228800,
1537315200, 1537401600, 1537488000, 1537747200, 1537833600, 1537920000,
1538006400, 1538092800, 1538352000, 1538438400, 1538524800, 1538611200,
1538697600, 1538956800, 1539043200, 1539129600, 1539216000, 1539302400,
1539561600, 1539648000, 1539734400, 1539820800, 1539907200, 1540166400,
1540252800, 1540339200, 1540425600, 1540512000, 1540771200, 1540857600,
1540944000, 1541030400, 1541116800, 1541376000, 1541462400, 1541548800,
1541635200, 1541721600, 1541980800, 1542067200, 1542153600, 1542240000,
1542326400, 1542585600, 1542672000, 1542758400, 1542931200, 1543190400,
1543276800, 1543363200, 1543449600, 1543536000), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", src = "yahoo", updated = structure(1544367929.32363, class = c("POSIXct",
"POSIXt")))
I have a dataset that consists of rows of 896 SNP in a genome. Then I have a probability value of each SNP coming from a specific founder. The founders are grouped in groups of 8.
I want to check for each SNP probability if the maximum value has a tie, so check for the highest value in each group of 8 founders and see if it is repeated. I am only interested in 2-way ties. Then I want to get the value of the tie, the SNP in which it appears and which founders have it.
The problem is that I have the data given to me in a way that all founder groups are in columns repeated next to each other with a layout like this :
SNP P1_1 P1_2 P1_3 P1_4 P1_5 P1_6 P1_7 P1_8 ... Pn_1 Pn_2 Pn_3 Pn_4 Pn_5 Pn_6 Pn7_ Pn8
Asd
FDA
FDG
GDE
GBD
SDF
I have worked it out by using loops, but in total for my dataset it takes 17 hours(!!!) to go through it, 896 SNPs and 600+ groups of 8 founders each.
Is there anyway to make it more efficient ? I was thinking something like melt() and having the final dataset in groups of 8 columns ? Would that be possible and even so would it make it more efficient ?
Here is what I have worked out so far:
require(reshape2)
A4 <- read.csv("sample.csv", header=TRUE)
SNP_count <-length(A4[,1])
A5 <- melt(A4)
#Give single index from 1-8 to each FOUNDER
A5[,4]<-rep(rep(seq(1,8,by=1),each=SNP_count),times=length(A5[,1])/SNP_count/8)
#Give a groupind number to each row so we know in which FOUNDER group it belongs
A5[,5]<-rep(seq(1,length(A5[,1])/SNP_count/8,by=1),each=SNP_count*8)
A5[,6]<-rep(seq(1,SNP_count))
colnames(A5) <- c("SNP","FOUNDER","PROB","FOUNDER_ID","GROUP_ID", "SNP_ID")
maxes<-NULL
x=1
i=1
for (x in 1:length(unique(A5$GROUP_ID))) {
for (i in 1:length(unique(A5$SNP_ID))) {
e<-NULL
e <- A5$PROB[A5$GROUP_ID==x & A5$SNP_ID==i] #save the rows of values here for each founder group
if(length(which(e == max(e))) == 2){
len <- length(which(e == max(e)))
max1 <- max(e)
founder <- as.character(A5[,2][A5$GROUP_ID==x & A5$SNP_ID==i])[1]
SNP_INFO <- as.character(A5[,1][A5$GROUP_ID==x & A5$SNP_ID==i][1])
ties <- length(which(e == max(e)))
tie1 <- which(e==max(e))[1]
tie2 <- which(e==max(e))[2]
maxes <- rbind(maxes, c(e, SNP_INFO, ties, tie1, tie2, max1, founder))
print(e)
}
}
}
From testing it seems that the line that makes it really slow is this :
e<-A5$PROB[A5$GROUP_ID==x & A5$SNP_ID==i]
Any help from anyone here would be amazingly appreciated.
dput results given below
structure(list(SNP = structure(c(571L, 690L, 7L, 204L, 317L,
39L, 559L, 657L, 221L, 470L, 576L, 49L, 413L, 460L, 606L, 348L,
111L, 129L, 30L, 290L, 291L, 767L, 96L, 172L, 38L, 48L, 54L,
144L, 273L, 644L), .Label = c("BobWhite_c11298_512", "BobWhite_c11935_137",
"BobWhite_c12428_371", "BobWhite_c1740_97", "BobWhite_c17852_511",
"BobWhite_c17879_519", "BobWhite_c18256_105", "BobWhite_c18408_199",
"BobWhite_c18593_955", "BobWhite_c1895_1953", "BobWhite_c21397_148",
"BobWhite_c28950_147", "BobWhite_c29419_116", "BobWhite_c30009_285",
"BobWhite_c30232_154", "BobWhite_c31500_144", "BobWhite_c34548_96",
"BobWhite_c34866_232", "BobWhite_c35093_176", "BobWhite_c35303_192",
"BobWhite_c42102_237", "BobWhite_c43213_184", "BobWhite_c43681_334",
"BobWhite_c45534_535", "BobWhite_c46361_331", "BobWhite_c47722_613",
"BobWhite_c5337_225", "BobWhite_c8340_511", "BobWhite_c9704_273",
"BobWhite_c9961_402", "BobWhite_c9992_862a", "BobWhite_rep_c49102_169",
"BobWhite_rep_c55551_53", "BobWhite_s65081_93", "BobWhite_s67516_159",
"BS00000445_51", "BS00001478_51", "BS00003733_51", "BS00003932_51",
"BS00003935_51", "BS00003956_51", "BS00003964_51", "BS00003971_51",
"BS00006822_51", "BS00007502_51", "BS00009649_51", "BS00009657_51",
"BS00009793_51", "BS00010059_51", "BS00010204_51", "BS00010531_51",
"BS00010854_51", "BS00011231_51", "BS00011516_51", "BS00011612_51",
"BS00012551_51", "BS00013584_51", "BS00017988_51", "BS00020459_51",
"BS00021694_51", "BS00021871_51", "BS00021909_51", "BS00021981_51",
"BS00022016_51", "BS00022029_51", "BS00022148_51", "BS00022159_51",
"BS00022182_51", "BS00022256_51", "BS00022273_51", "BS00022368_51",
"BS00022419_51", "BS00022424_51", "BS00022459_51", "BS00022516_51",
"BS00022528_51", "BS00022586_51", "BS00022703_51", "BS00022746_51",
"BS00022804_51", "BS00022845_51", "BS00022882_51", "BS00022884_51",
"BS00022908_51", "BS00022968_51", "BS00022989_51", "BS00023026_51",
"BS00023028_51", "BS00023189_51", "BS00023222_51", "BS00023337_51",
"BS00023511_51", "BS00025191_51", "BS00026189_51", "BS00026396_51",
"BS00027516_51", "BS00028660_51", "BS00029361_51", "BS00029569_51",
"BS00030652_51", "BS00030876_51", "BS00032025_51", "BS00032524_51",
"BS00032525_51", "BS00033658_51", "BS00034334_51", "BS00035364_51",
"BS00035576_51", "BS00036168_51", "BS00036492_51", "BS00037189_51",
"BS00037400_51", "BS00037537_51", "BS00038663_51", "BS00038664_51",
"BS00039357_51", "BS00039498_51", "BS00040798_51", "BS00041121_51",
"BS00041462_51", "BS00041742_51", "BS00042191_51", "BS00045327_51",
"BS00047668_51", "BS00047836_51", "BS00048031_51", "BS00048633_51",
"BS00048757_51", "BS00049420_51", "BS00049636_51", "BS00049637_51",
"BS00049977_51", "BS00055211_51", "BS00056089_51", "BS00057444_51",
"BS00057445_51", "BS00057523_51", "BS00057524_51", "BS00060029_51",
"BS00060391_51", "BS00061173_51", "BS00061179_51", "BS00062645_51",
"BS00062673_51", "BS00062808_51", "BS00063163_51", "BS00063300_51",
"BS00063696_51", "BS00064039_51", "BS00064422_51", "BS00064487_51",
"BS00064692_51", "BS00064703_51", "BS00065468_51", "BS00065673_51",
"BS00065734_51", "BS00065840_51", "BS00065932_51", "BS00065956_51",
"BS00066230_51", "BS00066475_51", "BS00066585_51", "BS00066714_51",
"BS00066800_51", "BS00067190_51", "BS00067215_51", "BS00067216_51",
"BS00067224_51", "BS00067499_51", "BS00067711_51", "BS00067748_51",
"BS00067777_51", "BS00067940_51", "BS00067997_51", "BS00068094_51",
"BS00068508_51", "BS00068520_51", "BS00069355_51", "BS00070464_51",
"BS00070511_51", "BS00070870_51", "BS00071422_51", "BS00071823_51",
"BS00071948_51", "BS00072186_51", "BS00072296_51", "BS00073009_51",
"BS00073525_51", "BS00073854_51", "BS00074617_51", "BS00074926_51",
"BS00075119_51", "BS00075515_51", "BS00075598_51", "BS00076772_51",
"BS00077819_51", "BS00078430_51", "BS00078669_51", "BS00080546_51",
"BS00080879_51", "BS00081418_51", "BS00081475_51", "BS00081610_51",
"BS00081981_51", "BS00082982_51", "BS00083279_51", "BS00083398_51",
"BS00084158_51", "BS00084159_51", "BS00085967_51", "BS00086050_51",
"BS00086051_51", "BS00086247_51", "BS00088755_51", "BS00088756_51",
"BS00089400_51", "BS00090225_51", "BS00090405_51", "BS00091002_51",
"BS00091887_51", "BS00092728_51", "BS00092735_51", "BS00093252_51",
"BS00093377_51", "BS00093871_51", "BS00093889_51", "BS00094366_51",
"BS00094523_51", "BS00095228_51", "BS00095423_51", "BS00096642_51",
"BS00097265_51", "BS00098840_51", "BS00099980_51", "BS00100626_51",
"BS00101363_51", "BS00101401_51", "BS00104401_51", "BS00105963_51",
"BS00105964_51", "BS00106008_51", "BS00106932_51", "BS00107444_51",
"BS00109084_51", "BS00109700_51", "BS00109935_51", "BS00110266_51",
"BS00110405_51", "BS00110452_51", "BS00110550_51", "BS00110564_51",
"BS00110638_51a", "CAP11_c1022_117", "CAP11_c1022_66", "CAP11_c3472_60",
"CAP11_c6193_232", "CAP11_rep_c6920_161", "CAP12_c1840_108",
"CAP12_c1860_280", "CAP7_c1238_51", "CAP7_c2141_129", "CAP7_c3178_52",
"CAP7_c3367_68", "CAP7_c915_121", "CAP7_rep_c12537_81", "CAP8_c1393_327",
"CAP8_c359_95", "CAP8_c665_242", "CAP8_c665_409", "CAP8_rep_c3652_80",
"CAP8_rep_c6382_237", "D_contig22919_290", "D_F5XZDLF02GN47Z_208",
"D_GBB4FNX02FX302_98", "Ex_c104581_457", "Ex_c15087_564", "Ex_c17586_108",
"Ex_c18484_2026", "Ex_c18484_2048", "Ex_c24554_1583", "Ex_c45438_377",
"Ex_c5858_1681", "Ex_c5858_953", "Ex_c66357_866", "Ex_c67794_487",
"Ex_c8871_1318", "Ex_c9685_1264", "Excalibur_c10079_1585", "Excalibur_c10383_432",
"Excalibur_c11079_749", "Excalibur_c11079_923", "Excalibur_c11505_155",
"Excalibur_c12875_864", "Excalibur_c13242_1178", "Excalibur_c13709_2568",
"Excalibur_c1529_1644", "Excalibur_c18089_1116", "Excalibur_c20250_313",
"Excalibur_c21051_515", "Excalibur_c24123_1597", "Excalibur_c24123_165",
"Excalibur_c2419_531", "Excalibur_c24354_465", "Excalibur_c24829_189",
"Excalibur_c25239_283", "Excalibur_c26754_433", "Excalibur_c29205_537",
"Excalibur_c29600_173", "Excalibur_c31571_136", "Excalibur_c33545_134",
"Excalibur_c39248_485", "Excalibur_c39309_171", "Excalibur_c39508_88",
"Excalibur_c39808_453", "Excalibur_c40694_473", "Excalibur_c41477_1272",
"Excalibur_c42951_136", "Excalibur_c42978_149", "Excalibur_c46082_440",
"Excalibur_c47078_512", "Excalibur_c47907_517", "Excalibur_c49743_97",
"Excalibur_c5097_1468", "Excalibur_c52446_519", "Excalibur_c5561_1013",
"Excalibur_c56240_176", "Excalibur_c60452_196", "Excalibur_c60581_62",
"Excalibur_c62042_175", "Excalibur_c64302_103", "Excalibur_c6501_477",
"Excalibur_c9000_209", "Excalibur_c91154_164", "Excalibur_c91154_175",
"Excalibur_c96921_206", "Excalibur_c9811_131", "Excalibur_c98205_83",
"Excalibur_rep_c103091_266", "Excalibur_rep_c103408_632a", "Excalibur_rep_c104884_1325",
"Excalibur_rep_c104884_417", "Excalibur_rep_c105085_102", "Excalibur_rep_c105978_544",
"Excalibur_rep_c110501_525", "Excalibur_rep_c112985_337", "Excalibur_rep_c116073_259",
"Excalibur_rep_c67269_496", "Excalibur_rep_c69004_1008", "Excalibur_s113043_59",
"GENE_1464_73", "GENE_1549_110", "GENE_1606_307", "GENE_1634_405",
"GENE_1661_228", "GENE_1674_631", "GENE_1820_661", "GENE_1826_718",
"GENE_1838_79", "GENE_2052_186", "GENE_2087_300", "GENE_3343_183",
"GENE_3665_61", "GENE_3939_576", "GENE_3939_653", "GENE_4252_246",
"GENE_4795_75", "IAAV1155", "IAAV1334", "IAAV1410", "IAAV1523",
"IAAV2646", "IAAV3826", "IAAV3900", "IAAV4190", "IAAV4286", "IAAV4781",
"IAAV488", "IAAV5030", "IAAV5207", "IAAV5370", "IAAV5507", "IAAV5729",
"IAAV5821", "IAAV5984", "IAAV6317", "IAAV6474", "IAAV6676", "IAAV6974",
"IAAV7454", "IAAV7930", "IAAV8170", "IAAV8218", "IAAV8351", "IAAV8407",
"IAAV8768", "IAAV8924", "IAAV902", "IAAV9044", "IAAV9068", "IACX11403",
"IACX2728", "IACX2831", "IACX464", "IACX5909", "IACX5968", "IACX6054",
"IACX6065", "IACX6092", "IACX6277", "IACX8519", "Jagger_c367_427",
"Jagger_c5842_90", "Jagger_c6722_104", "Jagger_c765_61", "Jagger_c791_62",
"JD_c1187_1398", "JG_c3077_225", "Ku_c103671_362", "Ku_c12191_1202",
"Ku_c13307_1116", "Ku_c14313_1194", "Ku_c17569_905", "Ku_c18096_552",
"Ku_c19456_645", "Ku_c26872_269", "Ku_c28597_514", "Ku_c41007_116",
"Ku_c4231_940", "Ku_c56370_1155", "Ku_c64839_240", "Ku_c68484_1276",
"Ku_c69970_624", "Ku_c69970_631", "Ku_c70534_1215", "Ku_c73010_143",
"Kukri_c10210_1387", "Kukri_c10210_1700", "Kukri_c10511_94",
"Kukri_c10751_1031", "Kukri_c10751_158", "Kukri_c10751_264",
"Kukri_c10751_860", "Kukri_c10977_990", "Kukri_c11709_874", "Kukri_c12079_204",
"Kukri_c12212_182", "Kukri_c13793_1152", "Kukri_c14012_358",
"Kukri_c14029_117", "Kukri_c14971_367", "Kukri_c15950_244", "Kukri_c17313_667",
"Kukri_c17966_561", "Kukri_c20889_526", "Kukri_c2123_1254", "Kukri_c23388_695",
"Kukri_c23833_181", "Kukri_c2454_59", "Kukri_c25564_185", "Kukri_c28650_111",
"Kukri_c28917_96", "Kukri_c30370_79", "Kukri_c31546_66", "Kukri_c33640_640",
"Kukri_c34195_357", "Kukri_c34845_242", "Kukri_c35426_507", "Kukri_c36418_392",
"Kukri_c3673_2442", "Kukri_c41361_186", "Kukri_c4324_74", "Kukri_c4568_1708",
"Kukri_c46833_105", "Kukri_c47643_920", "Kukri_c49927_151", "Kukri_c51247_322",
"Kukri_c51666_401", "Kukri_c5459_334", "Kukri_c54593_543", "Kukri_c54729_181",
"Kukri_c55381_67", "Kukri_c62467_362", "Kukri_c6288_364", "Kukri_c63259_151",
"Kukri_c63361_97", "Kukri_c64268_101", "Kukri_c68006_282", "Kukri_c80104_809",
"Kukri_c82097_197", "Kukri_c82117_279", "Kukri_c8242_730", "Kukri_c8400_2315",
"Kukri_c8465_54", "Kukri_c97654_90", "Kukri_rep_c102953_304",
"Kukri_rep_c103783_1380", "Kukri_rep_c105819_114", "Kukri_rep_c107195_111",
"Kukri_rep_c109051_116", "Kukri_rep_c110312_376", "Kukri_rep_c112061_617",
"Kukri_rep_c114028_94", "Kukri_rep_c69028_139", "Kukri_rep_c69028_1398",
"Kukri_rep_c69028_347", "Kukri_rep_c69970_717", "Kukri_rep_c70441_132",
"Kukri_rep_c70479_411", "Kukri_rep_c71916_1548", "Kukri_rep_c73936_154",
"Kukri_rep_c86903_184", "Kukri_rep_c87640_135", "Kukri_rep_c89183_282",
"Kukri_rep_c89509_83", "Kukri_s110037_62", "Kukri_s117946_404",
"Ra_c11263_2353", "Ra_c14565_1056", "Ra_c1619_250", "Ra_c1619_432",
"Ra_c20211_1415", "Ra_c23771_496", "Ra_c38505_544", "Ra_c38505_555",
"Ra_c3994_598", "Ra_c42858_503", "Ra_c42858_91", "Ra_c48730_581",
"Ra_c5515_1723", "Ra_c5515_2396", "Ra_c5515_2469", "Ra_c70087_485",
"Ra_c72106_227", "Ra_c73278_1234", "Ra_c88203_1055", "Ra_c88203_455",
"Ra_c88203_468", "RAC875_c10194_673", "RAC875_c10194_910", "RAC875_c10286_1247",
"RAC875_c10430_672", "RAC875_c14684_1128", "RAC875_c15109_106",
"RAC875_c1619_120", "RAC875_c1666_126", "RAC875_c17907_181",
"RAC875_c18570_893", "RAC875_c19138_402", "RAC875_c19570_671",
"RAC875_c20134_535", "RAC875_c22333_504", "RAC875_c23470_220",
"RAC875_c2464_274", "RAC875_c24982_202", "RAC875_c26514_127",
"RAC875_c27323_867", "RAC875_c2786_1097", "RAC875_c30443_966",
"RAC875_c3141_214", "RAC875_c31572_251", "RAC875_c31572_281",
"RAC875_c3427_734", "RAC875_c34649_380", "RAC875_c35074_452",
"RAC875_c36922_829", "RAC875_c371_251", "RAC875_c37118_595",
"RAC875_c39728_187", "RAC875_c45016_79", "RAC875_c46323_1996",
"RAC875_c46403_277", "RAC875_c47550_437", "RAC875_c47976_291",
"RAC875_c50787_113", "RAC875_c50864_1921", "RAC875_c51781_238",
"RAC875_c52195_324", "RAC875_c5310_1729", "RAC875_c53864_310",
"RAC875_c55313_89", "RAC875_c58159_521", "RAC875_c6445_275",
"RAC875_c66845_466", "RAC875_c66892_58", "RAC875_c67309_634",
"RAC875_c67998_96", "RAC875_c68056_81", "RAC875_c75663_115",
"RAC875_c787_431", "RAC875_c79551_167", "RAC875_c8010_155", "RAC875_c8174_1034",
"RAC875_c82493_67", "RAC875_c842_1476", "RAC875_c842_1516", "RAC875_c99055_69",
"RAC875_rep_c105428_270", "RAC875_rep_c108615_475", "RAC875_rep_c109228_400",
"RAC875_rep_c109288_122", "RAC875_rep_c109433_782", "RAC875_rep_c111243_125",
"RAC875_rep_c111698_383", "RAC875_rep_c111952_436", "RAC875_rep_c117959_132",
"RAC875_rep_c69730_522", "RAC875_rep_c70746_582", "RAC875_rep_c75557_177",
"RAC875_rep_c75768_245", "RAC875_rep_c77065_1532", "RAC875_rep_c77148_311",
"RAC875_rep_c81701_424", "RAC875_rep_c90531_283", "RAC875_s120038_124",
"RFL_Contig102_119", "RFL_Contig1175_354", "RFL_Contig1435_886",
"RFL_Contig1488_671", "RFL_Contig1798_1606", "RFL_Contig2394_439",
"RFL_Contig4282_1420", "RFL_Contig4399_956", "RFL_Contig4403_1034",
"RFL_Contig4921_2420", "RFL_Contig497_1114", "RFL_Contig5153_2667",
"RFL_Contig5153_958", "RFL_Contig5871_1650", "TA001038_0975",
"TA001383_0516", "TA002103_1262", "TA002702_0616", "TA003179_0872",
"TA003281_2379", "TA003550_0145", "TA003589_0518", "TA005161_0899",
"TA005199_0585", "TA005216_0272", "TA015264_0958", "Tdurum_contig10307_375",
"Tdurum_contig11121_739", "Tdurum_contig11121_834", "Tdurum_contig12008_842",
"Tdurum_contig13011_381", "Tdurum_contig13548_158", "Tdurum_contig25520_363",
"Tdurum_contig27982_568", "Tdurum_contig28699_54", "Tdurum_contig31235_99",
"Tdurum_contig33100_127", "Tdurum_contig42495_389", "Tdurum_contig45726_1116",
"Tdurum_contig5009_349", "Tdurum_contig5009_392", "Tdurum_contig5009_735",
"Tdurum_contig50376_375", "Tdurum_contig50392_1355", "Tdurum_contig50577_620",
"Tdurum_contig50617_713", "Tdurum_contig51995_377", "Tdurum_contig51995_474",
"Tdurum_contig55443_1361", "Tdurum_contig56373_348", "Tdurum_contig56731_335",
"Tdurum_contig57139_318", "Tdurum_contig57693_581", "Tdurum_contig57753_138",
"Tdurum_contig58326_467", "Tdurum_contig59531_892", "Tdurum_contig59531_914",
"Tdurum_contig59585_576", "Tdurum_contig59585_656", "Tdurum_contig59782_86",
"Tdurum_contig61299_55", "Tdurum_contig62502_90", "Tdurum_contig62557_263",
"Tdurum_contig63129_238", "Tdurum_contig67686_1149", "Tdurum_contig67686_1204",
"Tdurum_contig67686_633", "Tdurum_contig67686_792", "Tdurum_contig67686_851",
"Tdurum_contig68305_703", "Tdurum_contig68305_796", "Tdurum_contig68855_91",
"Tdurum_contig697_73", "Tdurum_contig76105_124", "Tdurum_contig76105_201",
"Tdurum_contig83209_316", "Tdurum_contig83663_371", "Tdurum_contig91865_242",
"Tdurum_contig93570_848", "Tdurum_contig9912_216", "Tdurum_contig9912_228",
"Tdurum_contig9912_451", "tplb0050h15_1287", "tplb0055d10_1024",
"wsnp_BE426222A_Ta_2_1", "wsnp_BE443568A_Ta_2_1", "wsnp_BE443568A_Ta_2_2",
"wsnp_BE443995B_Ta_2_2", "wsnp_BE490613A_Ta_2_1", "wsnp_BE494474A_Ta_2_2",
"wsnp_BE604885A_Ta_2_1", "wsnp_BE604885A_Ta_2_2", "wsnp_BF293133A_Ta_2_2",
"wsnp_BF429272A_Ta_2_1", "wsnp_BG262734A_Ta_2_3", "wsnp_BG262734A_Ta_2_7",
"wsnp_BM137927A_Ta_2_1", "wsnp_BQ171931A_Ta_2_1", "wsnp_CAP11_c2438_1258747",
"wsnp_CAP11_c318_261649", "wsnp_CAP11_rep_c4157_1965583", "wsnp_CAP11_rep_c4226_1995152",
"wsnp_CAP12_c15_9559", "wsnp_CAP12_rep_c8867_3720285", "wsnp_CAP8_c6939_3242530",
"wsnp_Ex_c10014_16477392", "wsnp_Ex_c10272_16842803", "wsnp_Ex_c10630_17338753",
"wsnp_Ex_c10667_17387885", "wsnp_Ex_c11039_17902115", "wsnp_Ex_c11085_17973016",
"wsnp_Ex_c11229_18163892", "wsnp_Ex_c11397_18400400", "wsnp_Ex_c1141_2191485",
"wsnp_Ex_c1149_2206471", "wsnp_Ex_c11807_18960045", "wsnp_Ex_c12269_19597341",
"wsnp_Ex_c12269_19597415", "wsnp_Ex_c12341_19693570", "wsnp_Ex_c12354_19711297",
"wsnp_Ex_c12750_20243224", "wsnp_Ex_c12948_20511479", "wsnp_Ex_c1335_2556442",
"wsnp_Ex_c13802_21639096", "wsnp_Ex_c14202_22144844", "wsnp_Ex_c14202_22145136",
"wsnp_Ex_c14202_22145805", "wsnp_Ex_c14340_22315611", "wsnp_Ex_c14400_22381382",
"wsnp_Ex_c14400_22381548", "wsnp_Ex_c14420_22402673", "wsnp_Ex_c15100_23284023",
"wsnp_Ex_c15269_23491104", "wsnp_Ex_c15269_23492289", "wsnp_Ex_c1533_2930233",
"wsnp_Ex_c1538_2937905", "wsnp_Ex_c15475_23756906", "wsnp_Ex_c15475_23757972",
"wsnp_Ex_c15674_24004513", "wsnp_Ex_c15674_24005648", "wsnp_Ex_c16079_24507688",
"wsnp_Ex_c1660_3159173", "wsnp_Ex_c16615_25147492", "wsnp_Ex_c18596_27457344",
"wsnp_Ex_c18637_27508578", "wsnp_Ex_c20273_29326769", "wsnp_Ex_c2148_4035913",
"wsnp_Ex_c22435_31629303", "wsnp_Ex_c22888_32105519", "wsnp_Ex_c24085_33332723",
"wsnp_Ex_c24731_33983680", "wsnp_Ex_c2502_4675968", "wsnp_Ex_c25132_34396655",
"wsnp_Ex_c26887_36107413", "wsnp_Ex_c27150_36365659", "wsnp_Ex_c28679_37784954",
"wsnp_Ex_c28930_38008757", "wsnp_Ex_c29742_38738725", "wsnp_Ex_c32003_40728918",
"wsnp_Ex_c3478_6369892", "wsnp_Ex_c35073_43285821", "wsnp_Ex_c35457_43602830",
"wsnp_Ex_c361_707953", "wsnp_Ex_c361_708712", "wsnp_Ex_c37208_45002588",
"wsnp_Ex_c41283_48140956", "wsnp_Ex_c41283_48141201", "wsnp_Ex_c47763_52874806",
"wsnp_Ex_c47907_52974924", "wsnp_Ex_c48136_53140385", "wsnp_Ex_c5047_8963671",
"wsnp_Ex_c51776_55603135", "wsnp_Ex_c53364_56625806", "wsnp_Ex_c55051_57706127",
"wsnp_Ex_c5623_9891427", "wsnp_Ex_c5623_9891516", "wsnp_Ex_c5623_9891584",
"wsnp_Ex_c56525_58609595", "wsnp_Ex_c57322_59083238", "wsnp_Ex_c57322_59084809",
"wsnp_Ex_c57322_59084950", "wsnp_Ex_c5929_10402147", "wsnp_Ex_c5997_10512308",
"wsnp_Ex_c60462_60905848", "wsnp_Ex_c6217_10848574", "wsnp_Ex_c6833_11782875",
"wsnp_Ex_c742_1458743", "wsnp_Ex_c763_1503467", "wsnp_Ex_c8409_14170476",
"wsnp_Ex_c88767_80001420", "wsnp_Ex_c8884_14841846", "wsnp_Ex_c9145_15214903",
"wsnp_Ex_c943_1808232", "wsnp_Ex_c943_1808577", "wsnp_Ex_c9458_15679797",
"wsnp_Ex_c9468_15696542", "wsnp_Ex_c9483_15722127", "wsnp_Ex_c9510_15761235",
"wsnp_Ex_rep_c101340_86719115", "wsnp_Ex_rep_c101340_86719239",
"wsnp_Ex_rep_c101942_87217430", "wsnp_Ex_rep_c102478_87635370",
"wsnp_Ex_rep_c106152_90334299", "wsnp_Ex_rep_c108072_91444417",
"wsnp_Ex_rep_c66357_64540369", "wsnp_Ex_rep_c66357_64540428",
"wsnp_Ex_rep_c66685_65003087", "wsnp_Ex_rep_c66685_65003254",
"wsnp_Ex_rep_c66685_65003625", "wsnp_Ex_rep_c66867_65267909",
"wsnp_Ex_rep_c66907_65324299", "wsnp_Ex_rep_c67349_65914945",
"wsnp_Ex_rep_c67460_66057400", "wsnp_Ex_rep_c67588_66227926",
"wsnp_Ex_rep_c67635_66291944", "wsnp_Ex_rep_c67635_66292308",
"wsnp_Ex_rep_c67635_66292689", "wsnp_Ex_rep_c67727_66398596",
"wsnp_Ex_rep_c67786_66472568", "wsnp_Ex_rep_c69034_67934852",
"wsnp_Ex_rep_c69034_67935465", "wsnp_Ex_rep_c69314_68244036",
"wsnp_Ex_rep_c69314_68244502", "wsnp_Ex_rep_c69577_68526990",
"wsnp_Ex_rep_c69752_68711460", "wsnp_Ex_rep_c69864_68823765",
"wsnp_Ex_rep_c69864_68824236", "wsnp_Ex_rep_c69864_68824319",
"wsnp_JD_c1187_1731186", "wsnp_JD_c29019_23208078", "wsnp_JD_c3034_4017676",
"wsnp_JD_c5699_6859527", "wsnp_JD_c7532_8615717", "wsnp_JD_c8207_9234643",
"wsnp_JD_c9434_10274598a", "wsnp_JD_c968_1427139", "wsnp_Ku_c10468_17301042",
"wsnp_Ku_c11052_18135847", "wsnp_Ku_c18497_27803432", "wsnp_Ku_c19456_28944589",
"wsnp_Ku_c23901_33846711", "wsnp_Ku_c30545_40369365", "wsnp_Ku_c32404_42016343",
"wsnp_Ku_c3286_6111360", "wsnp_Ku_c38911_47455674", "wsnp_Ku_c38911_47455924",
"wsnp_Ku_c40218_48484410", "wsnp_Ku_c4568_8243646", "wsnp_Ku_c4568_8243775",
"wsnp_Ku_c4886_8753646", "wsnp_Ku_c5243_9344536", "wsnp_Ku_c5359_9531713",
"wsnp_Ku_c5378_9559013", "wsnp_Ku_c7811_13387117", "wsnp_Ku_c8400_14280021",
"wsnp_Ku_c9433_15811664", "wsnp_Ku_rep_c104691_91086871", "wsnp_Ku_rep_c69970_69476502",
"wsnp_Ku_rep_c70479_70079622", "wsnp_Ku_rep_c71761_71496470",
"wsnp_Ra_c10669_17515792", "wsnp_Ra_c11291_18338838", "wsnp_Ra_c132_291198",
"wsnp_Ra_c16053_24607526", "wsnp_Ra_c16278_24893033", "wsnp_Ra_c16846_25598885",
"wsnp_Ra_c19079_28210829", "wsnp_Ra_c19079_28210937", "wsnp_Ra_c27831_37346894",
"wsnp_Ra_c29280_38672141", "wsnp_Ra_c35889_44345459", "wsnp_Ra_c44141_50623811",
"wsnp_Ra_c4858_8709000", "wsnp_Ra_c7280_12576178", "wsnp_Ra_rep_c106523_90273922",
"wsnp_Ra_rep_c72670_70836439a", "wsnp_RFL_Contig2011_1216801",
"wsnp_RFL_Contig2767_2518373", "wsnp_RFL_Contig3866_4228783",
"wsnp_RFL_Contig429_4978628", "wsnp_RFL_Contig4734_5671036",
"wsnp_RFL_Contig4814_5829093"), class = "factor"), MEL_004.3_haplotype1 = c(0.00033,
1e-05, 0, 0, 0, 0, 0, 0, 0.00013, 0.00013, 0.00014, 0.00022,
0.00022, 0.00022, 0.00022, 0.00027, 0.00027, 0.00023, 0.00023,
0.00023, 0.00022, 0.00022, 0.00015, 0.00014, 3e-05, 3e-05, 2e-05,
1e-05, 1e-05, 0), MEL_004.3_haplotype2 = c(0.00033, 1e-05, 0,
0, 0, 0, 0, 0, 0.00013, 0.00013, 0.00014, 0.00022, 0.00022, 0.00022,
0.00022, 0.00027, 0.00027, 0.00023, 0.00023, 0.00023, 0.00022,
0.00022, 0.00015, 0.00014, 3e-05, 3e-05, 2e-05, 1e-05, 1e-05,
0), MEL_004.3_haplotype3 = c(0.00033, 1e-05, 0, 0, 0, 0, 0, 0,
0.00013, 0.00013, 0.00014, 0.00022, 0.00022, 0.00022, 0.00022,
0.00027, 0.00027, 0.00023, 0.00023, 0.00023, 0.00022, 0.00022,
0.00015, 0.00014, 3e-05, 3e-05, 2e-05, 1e-05, 1e-05, 0), MEL_004.3_haplotype4 = c(0.00033,
1e-05, 0, 0, 0, 4e-05, 4e-05, 4e-05, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00021), MEL_004.3_haplotype5 = c(0.00033,
1e-05, 0, 0, 0, 4e-05, 4e-05, 4e-05, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), MEL_004.3_haplotype6 = c(0.96403,
0.96583, 0.96858, 0.97124, 0.97155, 0.97417, 0.97446, 0.97749,
0.98022, 0.9804, 0.98058, 0.98303, 0.98316, 0.9833, 0.98345,
0.98632, 0.98946, 0.99245, 0.99259, 0.99272, 0.99286, 0.993,
0.9958, 0.9961, 0.99927, 0.99939, 0.99948, 0.9996, 0.99972, 0.99973
), MEL_004.3_haplotype7 = c(0, 0, 0, 0, 0, 4e-05, 4e-05, 4e-05,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2e-05), MEL_004.3_haplotype8 = c(0.03431, 0.03407, 0.03141, 0.02873,
0.02844, 0.0257, 0.0254, 0.02237, 0.0194, 0.01919, 0.01897, 0.01631,
0.01616, 0.01602, 0.01586, 0.01286, 0.00971, 0.00683, 0.0067,
0.00658, 0.00646, 0.00633, 0.00374, 0.00346, 0.00065, 0.00055,
0.00045, 0.00034, 0.00024, 3e-05), MEL_005.3_haplotype1 = c(0.21684,
0.21698, 0.21721, 0.21746, 0.21741, 0.21704, 0.21694, 0.21582,
0.21465, 0.21458, 0.21448, 0.21345, 0.2134, 0.21333, 0.21328,
0.21213, 0.21094, 0.20988, 0.20983, 0.20977, 0.20973, 0.20969,
0.20874, 0.20864, 0.20762, 0.20758, 0.20754, 0.20752, 0.20747,
0.20744), MEL_005.3_haplotype2 = c(0.03821, 0.03799, 0.03566,
0.03332, 0.03305, 0.0306, 0.03031, 0.02743, 0.02462, 0.02441,
0.02421, 0.02168, 0.02154, 0.0214, 0.02124, 0.01837, 0.01534,
0.01254, 0.01241, 0.01229, 0.01218, 0.01205, 0.00953, 0.00925,
0.00652, 0.0064, 0.0063, 0.0062, 0.0061, 0.00599), MEL_005.3_haplotype3 = c(0.72948,
0.73078, 0.73836, 0.74606, 0.74668, 0.75236, 0.75276, 0.75674,
0.76033, 0.76059, 0.76085, 0.76416, 0.76434, 0.76454, 0.76474,
0.76859, 0.77275, 0.77666, 0.77684, 0.777, 0.77718, 0.77736,
0.78097, 0.78137, 0.7854, 0.78554, 0.7857, 0.78584, 0.78599,
0.78614), MEL_005.3_haplotype4 = c(0.0089, 0.0086, 0.00586, 0.00311,
0.0028, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0), MEL_005.3_haplotype5 = c(0.00588, 0.00558,
0.00281, 1e-05, 2e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), MEL_005.3_haplotype6 = c(0.00033,
1e-05, 0, 0, 0, 0, 0, 0, 0.00018, 0.00019, 2e-04, 3e-04, 3e-04,
0.00031, 0.00032, 0.00038, 0.00038, 0.00033, 0.00032, 0.00031,
0.00031, 3e-04, 0.00021, 2e-04, 4e-05, 2e-05, 2e-05, 1e-05, 1e-05,
0), MEL_005.3_haplotype7 = c(3e-05, 5e-05, 6e-05, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), MEL_005.3_haplotype8 = c(0.00033, 1e-05, 0, 0, 0, 0, 0,
0, 0.00022, 0.00024, 0.00025, 4e-04, 0.00041, 0.00042, 0.00042,
0.00053, 6e-04, 6e-04, 6e-04, 6e-04, 6e-04, 6e-04, 0.00054, 0.00053,
0.00043, 0.00043, 0.00042, 0.00042, 0.00041, 0.00041), MEL_005.4_haplotype1 = c(0.16705,
0.16711, 0.16662, 0.16614, 0.16603, 0.16508, 0.16492, 0.16332,
0.16169, 0.16156, 0.16144, 0.16, 0.15991, 0.15983, 0.15975, 0.15811,
0.1564, 0.15485, 0.15479, 0.15472, 0.15464, 0.15458, 0.1532,
0.15304, 0.15154, 0.15148, 0.15142, 0.15138, 0.15132, 0.15126
), MEL_005.4_haplotype2 = c(0.03823, 0.03801, 0.03569, 0.03335,
0.03308, 0.0306, 0.03032, 0.02746, 0.02463, 0.02443, 0.02423,
0.0217, 0.02156, 0.02141, 0.02126, 0.01837, 0.01535, 0.01256,
0.01243, 0.0123, 0.01218, 0.01206, 0.00955, 0.00925, 0.0065,
0.00641, 0.00632, 0.0062, 0.0061, 0.006), MEL_005.4_haplotype3 = c(0.77923,
0.78063, 0.78893, 0.79736, 0.79805, 0.80432, 0.80476, 0.80922,
0.81328, 0.81357, 0.81386, 0.8176, 0.81781, 0.81801, 0.81825,
0.82258, 0.82726, 0.83167, 0.83187, 0.83205, 0.83224, 0.83244,
0.8365, 0.83695, 0.84147, 0.84164, 0.84181, 0.84198, 0.84215,
0.8423), MEL_005.4_haplotype4 = c(0.00889, 0.00861, 0.00587,
0.00312, 0.0028, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0), MEL_005.4_haplotype5 = c(0.00589,
0.00559, 0.00282, 1e-05, 2e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), MEL_005.4_haplotype6 = c(0.00033,
1e-05, 0, 0, 0, 0, 0, 0, 0.00018, 0.00019, 2e-04, 3e-04, 3e-04,
0.00031, 0.00031, 0.00037, 0.00037, 0.00032, 0.00031, 0.00031,
0.00031, 3e-04, 0.00021, 2e-04, 4e-05, 2e-05, 2e-05, 1e-05, 1e-05,
0), MEL_005.4_haplotype7 = c(3e-05, 5e-05, 6e-05, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0)), .Names = c("SNP", "MEL_004.3_haplotype1", "MEL_004.3_haplotype2",
"MEL_004.3_haplotype3", "MEL_004.3_haplotype4", "MEL_004.3_haplotype5",
"MEL_004.3_haplotype6", "MEL_004.3_haplotype7", "MEL_004.3_haplotype8",
"MEL_005.3_haplotype1", "MEL_005.3_haplotype2", "MEL_005.3_haplotype3",
"MEL_005.3_haplotype4", "MEL_005.3_haplotype5", "MEL_005.3_haplotype6",
"MEL_005.3_haplotype7", "MEL_005.3_haplotype8", "MEL_005.4_haplotype1",
"MEL_005.4_haplotype2", "MEL_005.4_haplotype3", "MEL_005.4_haplotype4",
"MEL_005.4_haplotype5", "MEL_005.4_haplotype6", "MEL_005.4_haplotype7"
), row.names = c(NA, 30L), class = "data.frame")
Thank you
You can do this efficiently with the dplyr package, after first gathering all probabilities into a single column (very similar to what you were doing with melt):
library(dplyr)
library(tidyr)
pairs <- A4 %>%
gather(individual, value, -SNP) %>%
separate(individual, c("group", "founder"), sep = "_haplotype") %>%
group_by(SNP, group) %>%
filter(value == max(value)) %>%
filter(n() == 2) %>%
ungroup() %>%
arrange(SNP)
(By the way, the ungroup and arrange aren't strictly necessary here: it is just nice to have it sorted by SNP when you view the output).
The subset of data you posted had no 2-way ties for first place. But we could add 5 ties artificially with:
A4[1:5, 2:3] <- .999
At this point, the output would look like:
Source: local data frame [10 x 4]
SNP group founder value
(fctr) (chr) (chr) (dbl)
1 BobWhite_c18256_105 MEL_004.3 1 0.999
2 BobWhite_c18256_105 MEL_004.3 2 0.999
3 BS00081981_51 MEL_004.3 1 0.999
4 BS00081981_51 MEL_004.3 2 0.999
5 Excalibur_c42951_136 MEL_004.3 1 0.999
6 Excalibur_c42951_136 MEL_004.3 2 0.999
7 RAC875_c46403_277 MEL_004.3 1 0.999
8 RAC875_c46403_277 MEL_004.3 2 0.999
9 Tdurum_contig83209_316 MEL_004.3 1 0.999
10 Tdurum_contig83209_316 MEL_004.3 2 0.999
This shows pairs of probability that were tied within a SNP and group. Incidentally, you might prefer to reorganize this into one-row-per-tie, which could be done with tidyr's spread:
pair_ties <- pairs %>%
group_by(SNP, group) %>%
mutate(column = c("founder1", "founder2")) %>%
spread(column, founder)
Which would have output:
Source: local data frame [5 x 5]
SNP group value founder1 founder2
(fctr) (chr) (dbl) (chr) (chr)
1 BobWhite_c18256_105 MEL_004.3 0.999 1 2
2 BS00081981_51 MEL_004.3 0.999 1 2
3 Excalibur_c42951_136 MEL_004.3 0.999 1 2
4 RAC875_c46403_277 MEL_004.3 0.999 1 2
5 Tdurum_contig83209_316 MEL_004.3 0.999 1 2
As a quick explanation of how this works- it relies on the dplyr package, which defines a grammar for data manipulation in terms of sequential steps, piped together with the %>% "pipe" operator. One of the best intros is here. Those are worth reading in general for what each function does. In this case, imagine it happening in four stages:
x1 <- A4 %>%
gather(individual, value, -SNP) %>%
separate(individual, c("group", "founder"), sep = "_haplotype")
These steps do the same thing as melt in your code: they gather all the probabilities into a single column called value, and move the column names into a column called individual alongside it. It then separates the individual into a "group" column (your 600+ groups) and a "founder" column (1-8).
x2 <- x1 %>%
group_by(SNP, group) %>%
filter(value == max(value))
This says you want to look within each group made up of a unique SNP and group. This is taking the place of your nested for loops above. Within each group, it filters for rows where the value column is as large as the maximum.
x3 <- x2 %>%
filter(n() == 2)
The data frame is still grouped, and only has ties for first-place, and this is saying you want to include only groups of size 2. At this point, the work is done, and the last two steps just sort it by SNP to make it more readable:
result <- x3 %>%
ungroup() %>%
arrange(SNP)
Incidentally, to estimate how long this would take on your data, I simulated some data of the same size as yours:
groups <- 600
founders <- 8
SNPs <- 896
vals <- as.data.frame(replicate(groups * founders, sample(10, SNPs, replace = TRUE) / 10))
names(vals) <- paste0("P", rep(seq_len(groups), each = founders), "_", seq_len(founders))
SNPnames <- paste("SNP", seq_len(SNPs))
A4 <- cbind(SNP = SNPnames, vals)
On this A4, the code took about 30 seconds to run on my machine.