R: Integrate two lists subelements - r

Each element of the pp list has five subelements, each containing a vector of values called expr. Also, list iid contains one element with the same number and length of sub-elements of each element in pp. In order to integrate two lists, I want for each element of pp, the characters in the iid become a column name and the corresponding values in the pp to become rows like a data frame. At the end, all the values should be comncatenated and divided in five as it is in the inputs.
## pp list
pp <- list(ENSG00000141956 = list(foldSet_1 = structure(list(expr = c(0.3803048,
-0.1005805, -0.1388998, -0.439475, 0.3326845, -0.6787136, -0.8862647,
0.5526945, 0.4432067, -0.4434515862, -0.3608854, 0.0120686657,
0.09344841, 0.400137, 0.7890199, -0.492058, 0.07042376, 0.3025703,
0.1189347, -0.795448, -0.102853, 0.677594, -0.4110812)), row.names = c(NA,
-23L), class = c("tbl_df", "tbl", "data.frame")), foldSet_2 = structure(list(
expr = c(0.3910626, 0.4011977, -0.5375317082, 1.118997, -0.714867812,
0.7692958314, -0.7411604, -0.105918, -0.06774316, 0.37792,
-1.50101, 0.4659521, 0.05462016, 0.8191656, 0.2534708, -0.7851615,
0.06491725, -0.1145606, 0.2031628, -0.3784291, 1.75129, -0.2781814
)), row.names = c(NA, -22L), class = c("tbl_df", "tbl", "data.frame"
)), foldSet_3 = structure(list(expr = c(0.1346737, -0.3018867,
2.008637597, 0.2174854, 0.1817713, 0.2068479, 0.4385861, -0.6867911553,
-0.04973609, 0.9683988, -0.004377791, 0.4063974, -0.08958473,
0.2791352, -0.6540139556, 0.2491497, -0.3315336, 0.5217149, -0.3263807,
-0.4260331, 0.2909981, 0.2420486, 0.03705211)), row.names = c(NA,
-23L), class = c("tbl_df", "tbl", "data.frame")), foldSet_4 = structure(list(
expr = c(0.01042395, -0.4773195, 0.08209318, -0.7586276,
0.1575954, -0.7206272, 0.2283236, -0.1310485, 0.422618, 0.0108831611,
0.5423006, -0.1537052, -0.206502, 0.196586, -0.8410328, 0.09204746,
-0.7454582, 0.1416914, -0.8276129, 0.8363268, -0.7257737,
0.3657267)), row.names = c(NA, -22L), class = c("tbl_df",
"tbl", "data.frame")), foldSet_5 = structure(list(expr = c(1.265001,
-0.8963425427, 0.2428121, 0.2942902, -0.01086715, 0.5085538,
0.6372121, 0.8329305, 0.1185538, -0.5767332, 0.3843823, 0.2350104,
-0.2325683, -0.1219577, 0.6623785, -0.5607696, -1.5371637259,
-1.657621852, -0.01256456, 0.4563003, -0.7890026, -1.197397,
0.3742298)), row.names = c(NA, -23L), class = c("tbl_df", "tbl",
"data.frame"))), ENSG00000141959 = list(foldSet_1 = structure(list(
expr = c(-0.3003046, 0.005579603, -0.2596373, -0.3522028,
0.1879026, 0.1967071, -0.4713157, -0.3310353, -0.1003091,
0.3832126993, -0.05301061, -0.3635412607, 0.4025212, 0.1362349,
-0.1587811, 0.3373843, 0.1998857, 0.4367898, -0.5611188,
0.02719134, -0.1471497, 0.12489, 0.6190356)), row.names = c(NA,
-23L), class = c("tbl_df", "tbl", "data.frame")), foldSet_2 = structure(list(
expr = c(0.0579663, 0.3904131, 0.2544079194, -0.1574236,
0.69677048, -0.0876293718, -0.5368353, 0.225058, -0.5255409,
-0.3314226, -1.622316, 0.1064199, 0.1061926, 0.3527317, -0.4675344,
0.1723076, -0.1159002, -0.006312083, -0.2083593, -0.00007146444,
0.1268512, -0.07700766)), row.names = c(NA, -22L), class = c("tbl_df",
"tbl", "data.frame")), foldSet_3 = structure(list(expr = c(0.1401876,
-0.3250818, 0.5946272517, -0.2694272, -0.2912538, -0.0780406,
0.3063621, 0.0676218118, -0.2015818, 0.1549354, 0.5281673, 1.037816,
-0.3362126, -0.4971578, -0.0889611491, -0.0641598, 0.7628252,
-0.2208091, -0.7417216, -0.3509665, 0.07412728, -0.4002744, -0.5406274
)), row.names = c(NA, -23L), class = c("tbl_df", "tbl", "data.frame"
)), foldSet_4 = structure(list(expr = c(-0.350688, 0.5425585,
0.2550953, 0.6242607, 0.6671248, -0.3640666, 0.3625934, -0.02385531,
0.2368257, -0.1671464501, 0.1443962, 0.2876699, 0.5233608, 0.411042,
-0.6771724, 0.04496645, -0.7915447, -0.4581436, -0.008061834,
0.156641, 0.5718667, -0.8583139)), row.names = c(NA, -22L), class = c("tbl_df",
"tbl", "data.frame")), foldSet_5 = structure(list(expr = c(0.5290703,
-0.1029373935, 0.1481799, -0.3074795, 0.825576, 0.3023727, 0.2402515,
0.09724703, 0.09133488, 0.5141968, 0.362571, -0.1941567, -0.09751567,
-0.9363854, -0.03207956, 0.6985924, -0.6445457624, -0.0887025618,
0.01355917, 0.002195536, -0.05979083, 0.1404834, -0.2035347)), row.names = c(NA,
-23L), class = c("tbl_df", "tbl", "data.frame"))))
## iid list
iid <- list(foldSet_1 = c("GTEX-11EQ9", "GTEX-12WSJ", "GTEX-1EKGG",
"GTEX-1EU9M", "GTEX-1EWIQ", "GTEX-1F5PK", "GTEX-1GMRU", "GTEX-1GTWX",
"GTEX-S95S", "GTEX-SN8G", "GTEX-T5JC", "GTEX-T6MO", "GTEX-TKQ2",
"GTEX-U3ZM", "GTEX-V1D1", "GTEX-WFG7", "GTEX-WFG8", "GTEX-WFJO",
"GTEX-WOFM", "GTEX-Y5V6", "GTEX-Y8LW", "GTEX-ZC5H", "GTEX-ZXES"
), foldSet_2 = c("GTEX-11EM3", "GTEX-11EMC", "GTEX-11ZTT", "GTEX-1212Z",
"GTEX-12696", "GTEX-1269C", "GTEX-1GF9U", "GTEX-1GMR8", "GTEX-1I4MK",
"GTEX-S4Q7", "GTEX-U3ZG", "GTEX-WWTW", "GTEX-WZTO", "GTEX-X4EO",
"GTEX-XPT6", "GTEX-Y5V5", "GTEX-YB5K", "GTEX-YEC4", "GTEX-ZF3C",
"GTEX-ZG7Y", "GTEX-ZP4G", "GTEX-ZT9W"), foldSet_3 = c("GTEX-11I78",
"GTEX-11VI4", "GTEX-12C56", "GTEX-13111", "GTEX-1399R", "GTEX-1FIGZ",
"GTEX-1GN2E", "GTEX-RUSQ", "GTEX-T5JW", "GTEX-UPJH", "GTEX-V955",
"GTEX-VUSG", "GTEX-W5WG", "GTEX-WRHK", "GTEX-XBED", "GTEX-XMK1",
"GTEX-XQ3S", "GTEX-XXEK", "GTEX-Y8DK", "GTEX-ZEX8", "GTEX-ZPCL",
"GTEX-ZQG8", "GTEX-ZTPG"), foldSet_4 = c("GTEX-1122O", "GTEX-1211K",
"GTEX-12WSL", "GTEX-T6MN", "GTEX-TMZS", "GTEX-UPK5", "GTEX-WFON",
"GTEX-WHSB", "GTEX-WHWD", "GTEX-WY7C", "GTEX-WYVS", "GTEX-X15G",
"GTEX-XGQ4", "GTEX-Y9LG", "GTEX-YEC3", "GTEX-ZDTS", "GTEX-ZDTT",
"GTEX-ZF2S", "GTEX-ZLV1", "GTEX-ZPIC", "GTEX-ZT9X", "GTEX-ZUA1"
), foldSet_5 = c("GTEX-12WSN", "GTEX-1F48J", "GTEX-1F52S", "GTEX-1GMR3",
"GTEX-SUCS", "GTEX-U3ZH", "GTEX-U3ZN", "GTEX-WEY5", "GTEX-WH7G",
"GTEX-X4EP", "GTEX-X4LF", "GTEX-X5EB", "GTEX-XBEW", "GTEX-XLM4",
"GTEX-Y5LM", "GTEX-Y8E4", "GTEX-YF7O", "GTEX-ZF29", "GTEX-ZTSS",
"GTEX-ZTTD", "GTEX-ZV6S", "GTEX-ZVT2", "GTEX-ZVZP"))
The desired output looks like this:
pp_out <- list(ENSG00000141956 = structure(list(`GTEX-11EQ9` = 0.00272564851305302,
`GTEX-12WSJ` = 0.00272564851305302, `GTEX-1EKGG` = 0.0202754075985887,
`GTEX-1EU9M` = 0.00676249893692591, `GTEX-1EWIQ` = 0.00336835547752925,
`GTEX-1F5PK` = 0.00336835547752925, `GTEX-1GMRU` = 0.0191065491234794,
`GTEX-1GTWX` = 0.00272564851305302, `GTEX-S95S` = 0.00503517684692274,
`GTEX-SN8G` = 0.0150945626471007, `GTEX-T5JC` = 0.00602406792927852,
`GTEX-T6MO` = 0.00272564851305302, `GTEX-TKQ2` = 0.00272564851305302,
`GTEX-U3ZM` = 0.00272564851305302, `GTEX-V1D1` = 0.00300074743348399,
`GTEX-WFG7` = 0.00300074743348399, `GTEX-WFG8` = 0.00327584635391496,
`GTEX-WFJO` = 0.00300074743348399, `GTEX-WOFM` = 0.00272564851305302,
`GTEX-Y5V6` = 0.00614716297153329, `GTEX-Y8LW` = 0.0208907435639813,
`GTEX-ZC5H` = 0.00879692835036466, `GTEX-ZXES` = 0.00574896900884754,
`GTEX-11EM3` = -0.0149845730327965, `GTEX-11EMC` = -0.013847280341284,
`GTEX-11ZTT` = -0.0275325515044248, `GTEX-1212Z` = -0.0141988014913753,
`GTEX-12696` = -0.0136176647967972, `GTEX-1269C` = -0.0275325515044248,
`GTEX-1GF9U` = -0.0153360941828878, `GTEX-1GMR8` = -0.0136116558238996,
`GTEX-1I4MK` = -0.0138532893141817, `GTEX-S4Q7` = -0.0151539874321891,
`GTEX-U3ZG` = -0.0138532893141817, `GTEX-WWTW` = -0.027416654871718,
`GTEX-WZTO` = -0.0215030592385638, `GTEX-X4EO` = -0.0205524436634252,
`GTEX-XPT6` = -0.0136116558238996, `GTEX-Y5V5` = -0.0174136560129391,
`GTEX-YB5K` = -0.0138532893141817, `GTEX-YEC4` = -0.0136176647967972,
`GTEX-ZF3C` = -0.0208273881822836, `GTEX-ZG7Y` = -0.0136176647967972,
`GTEX-ZP4G` = -0.0250634259373212, `GTEX-ZT9W` = -0.0136176647967972,
`GTEX-11I78` = -0.037929571081887, `GTEX-11VI4` = -0.0352737894666712,
`GTEX-12C56` = -0.0364115473528404, `GTEX-13111` = -0.0353679266239015,
`GTEX-1399R` = -0.0376033957001448, `GTEX-1FIGZ` = -0.0308210759870506,
`GTEX-1GN2E` = -0.0376033957001448, `GTEX-RUSQ` = -0.0376033957001448,
`GTEX-T5JW` = -0.0420643633134619, `GTEX-UPJH` = -0.0360853719710982,
`GTEX-V955` = -0.037929571081887, `GTEX-VUSG` = -0.0360853719710982,
`GTEX-W5WG` = -0.0330565450632938, `GTEX-WRHK` = -0.037929571081887,
`GTEX-XBED` = -0.037929571081887, `GTEX-XMK1` = -0.0352737894666712,
`GTEX-XQ3S` = -0.0350417512421593, `GTEX-XXEK` = -0.0376033957001448,
`GTEX-Y8DK` = -0.0376033957001448, `GTEX-ZEX8` = -0.0360853719710982,
`GTEX-ZPCL` = -0.0364115473528404, `GTEX-ZQG8` = -0.0381176463621845,
`GTEX-ZTPG` = -0.037929571081887, `GTEX-1122O` = 0.0311974749143465,
`GTEX-1211K` = 0.0302892560510041, `GTEX-12WSL` = 0.0310530889747851,
`GTEX-T6MN` = 0.0253053324056306, `GTEX-TMZS` = 0.0251609464660692,
`GTEX-UPK5` = 0.0250389673364521, `GTEX-WFON` = 0.0251609464660692,
`GTEX-WHSB` = 0.0310530889747851, `GTEX-WHWD` = 0.0253053324056306,
`GTEX-WY7C` = 0.0310530889747851, `GTEX-WYVS` = 0.0360370126201587,
`GTEX-X15G` = 0.0253053324056306, `GTEX-XGQ4` = 0.0254497183451919,
`GTEX-Y9LG` = 0.0236698466255728, `GTEX-YEC3` = 0.0250389673364521,
`GTEX-ZDTS` = 0.0302892560510041, `GTEX-ZDTT` = 0.02716525500288,
`GTEX-ZF2S` = 0.0302892560510041, `GTEX-ZLV1` = 0.0250389673364521,
`GTEX-ZPIC` = 0.0254497183451919, `GTEX-ZT9X` = 0.0302892560510041,
`GTEX-ZUA1` = 0.0311974749143465, `GTEX-12WSN` = 0.0196357496993677,
`GTEX-1F48J` = 0.0167271490318362, `GTEX-1F52S` = 0.0168263419569211,
`GTEX-1GMR3` = 0.0199993991223454, `GTEX-SUCS` = 0.0167271490318362,
`GTEX-U3ZH` = 0.0166279561067514, `GTEX-U3ZN` = 0.0168263419569211,
`GTEX-WEY5` = 0.0218122431555806, `GTEX-WH7G` = 0.0169603561059156,
`GTEX-X4EP` = 0.0167271490318362, `GTEX-X4LF` = 0.0168263419569211,
`GTEX-X5EB` = 0.0231724562877696, `GTEX-XBEW` = 0.0187383789152412,
`GTEX-XLM4` = 0.0167271490318362, `GTEX-Y5LM` = 0.0168263419569211,
`GTEX-Y8E4` = 0.0121019992430171, `GTEX-YF7O` = 0.0168263419569211,
`GTEX-ZF29` = 0.0168980287283542, `GTEX-ZTSS` = 0.0166279561067514,
`GTEX-ZTTD` = 0.0168263419569211, `GTEX-ZV6S` = 0.0199993991223454,
`GTEX-ZVT2` = 0.0195049035328895, `GTEX-ZVZP` = 0.0199993991223454), class = "data.frame", row.names = c(NA,
-1L)), ENSG00000141959 = structure(list(`GTEX-11EQ9` = 0.00386794757219419,
`GTEX-12WSJ` = 0.00331068544990299, `GTEX-1EKGG` = 0.00549727349038067,
`GTEX-1EU9M` = -0.00220598881051638, `GTEX-1EWIQ` = -0.00220598881051638,
`GTEX-1F5PK` = -0.00047576052598424, `GTEX-1GMRU` = -0.000019400770038708,
`GTEX-1GTWX` = -0.00265461664506892, `GTEX-S95S` = -0.000205735129200752,
`GTEX-SN8G` = -0.00148165048282797, `GTEX-T5JC` = -0.00164872668822519,
`GTEX-T6MO` = -0.0013787012914417, `GTEX-TKQ2` = -0.00265461664506892,
`GTEX-U3ZM` = -0.00164872668822519, `GTEX-V1D1` = -0.00220598881051638,
`GTEX-WFG7` = -0.00103302264827544, `GTEX-WFG8` = -0.000205735129200752,
`GTEX-WFJO` = 0.00659503688105354, `GTEX-WOFM` = 0.00169406666058391,
`GTEX-Y5V6` = 0.00659503688105354, `GTEX-Y8LW` = 0.00269498140995324,
`GTEX-ZC5H` = 0.00225132878287511, `GTEX-ZXES` = 0.00549727349038067,
`GTEX-11EM3` = 0.0210024880281395, `GTEX-11EMC` = 0.0171347306001959,
`GTEX-11ZTT` = 0.018137007193539, `GTEX-1212Z` = 0.0228033435746737,
`GTEX-12696` = 0.0205811017648125, `GTEX-1269C` = 0.0168279586537404,
`GTEX-1GF9U` = 0.0205811017648125, `GTEX-1GMR8` = 0.0175495081991909,
`GTEX-1I4MK` = 0.0183843909485424, `GTEX-S4Q7` = 0.0211578279565913,
`GTEX-U3ZG` = 0.0177114567919747, `GTEX-WWTW` = 0.0204149125032887,
`GTEX-WZTO` = 0.0164914915754566, `GTEX-X4EO` = 0.0178224278158885,
`GTEX-XPT6` = 0.0198274900394434, `GTEX-Y5V5` = 0.0177114567919747,
`GTEX-YB5K` = 0.0180479238702585, `GTEX-YEC4` = 0.0168279586537404,
`GTEX-ZF3C` = 0.0214942950348751, `GTEX-ZG7Y` = 0.0171347306001959,
`GTEX-ZP4G` = 0.0171347306001959, `GTEX-ZT9W` = 0.0246041991212079,
`GTEX-11I78` = 0.00746714052332263, `GTEX-11VI4` = 0.00818008340245513,
`GTEX-12C56` = 0.0123095880229919, `GTEX-13111` = 0.00943601338470202,
`GTEX-1399R` = 0.00897187247388116, `GTEX-1FIGZ` = 0.00795749001625596,
`GTEX-1GN2E` = 0.00943601338470202, `GTEX-RUSQ` = 0.00780432935650995,
`GTEX-T5JW` = 0.00563415692477041, `GTEX-UPJH` = 0.00671924314064018,
`GTEX-V955` = 0.00904257623212573, `GTEX-VUSG` = 0.00994736151433579,
`GTEX-W5WG` = 0.00971976985656361, `GTEX-WRHK` = 0.00671924314064018,
`GTEX-XBED` = 0.00941833027807091, `GTEX-XMK1` = 0.00780432935650995,
`GTEX-XQ3S` = 0.00977320221788934, `GTEX-XXEK` = 0.00671924314064018,
`GTEX-Y8DK` = 0.00818008340245513, `GTEX-ZEX8` = 0.00795749001625596,
`GTEX-ZPCL` = 0.0100569586897509, `GTEX-ZQG8` = 0.00746714052332263,
`GTEX-ZTPG` = 0.00904257623212573, `GTEX-1122O` = -0.0148396051801961,
`GTEX-1211K` = -0.0141597831410679, `GTEX-12WSL` = -0.0141750601473065,
`GTEX-T6MN` = -0.0141133976650269, `GTEX-TMZS` = -0.012512044067443,
`GTEX-UPK5` = -0.0141133976650269, `GTEX-WFON` = -0.0143460749121506,
`GTEX-WHSB` = -0.0139271058939441, `GTEX-WHWD` = -0.00993393444101102,
`GTEX-WY7C` = -0.00920772692584177, `GTEX-WYVS` = -0.0144923036878726,
`GTEX-X15G` = -0.00993393444101102, `GTEX-XGQ4` = -0.0135798044016206,
`GTEX-Y9LG` = -0.0148396051801961, `GTEX-YEC3` = -0.0150722824273198,
`GTEX-ZDTS` = -0.0144923036878726, `GTEX-ZDTT` = -0.0143060119167898,
`GTEX-ZF2S` = -0.00955502841816534, `GTEX-ZLV1` = -0.0141133976650269,
`GTEX-ZPIC` = -0.0135798044016206, `GTEX-ZT9X` = -0.00920772692584177,
`GTEX-ZUA1` = -0.0152185112030418, `GTEX-12WSN` = -0.0151287367580205,
`GTEX-1F48J` = -0.0164455761832253, `GTEX-1F52S` = -0.016964848400182,
`GTEX-1GMR3` = -0.0151522926443206, `GTEX-SUCS` = -0.0126712489200476,
`GTEX-U3ZH` = -0.0144246945509821, `GTEX-U3ZN` = -0.0151522926443206,
`GTEX-WEY5` = -0.0155466417925569, `GTEX-WH7G` = -0.0113544094948428,
`GTEX-X4EP` = -0.0151287367580205, `GTEX-X4LF` = -0.0142298023673521,
`GTEX-X5EB` = -0.0164220202969252, `GTEX-XBEW` = -0.0106503672878044,
`GTEX-XLM4` = -0.0156480089749772, `GTEX-Y5LM` = -0.0164220202969252,
`GTEX-Y8E4` = -0.0140893159157665, `GTEX-YF7O` = -0.0164220202969252,
`GTEX-ZF29` = -0.0156480089749772, `GTEX-ZTSS` = -0.0156715648612773,
`GTEX-ZTTD` = -0.0170940674370707, `GTEX-ZV6S` = -0.0142298023673521,
`GTEX-ZVT2` = -0.0170940674370707, `GTEX-ZVZP` = -0.01773885972213), class = "data.frame", row.names = c(NA,
-1L)))

Related

create a column and index it with an ID in R

I have several datasets that needs label (i.e., ID1 .. IDn). For example the following code belongs to a certain dataset where I just want to add an extra column that labels all the observations with IDx.
In total I got 42 datasets. This means that I need to label al of those 42 datasets with an unique ID.
structure(list(X = 1:5, x1.time = c("00:00:00", "00:01:00", "00:02:00",
"00:03:00", "00:04:00"), x1.AI_mean = c(0.323351574525762, 0.284159071937747,
0.239749146757921, 0.230766586001914, 0.244456920325771), x1.MAD_mean = c(0.00341506508299082,
0.00302928679541095, 0.00278424196850715, 0.00269385572703841,
0.00270493856606347), x1.SD_mean = c(0.00477593690534784, 0.00405971881709533,
0.00354415353173061, 0.00350825365755234, 0.00361817148789133
), x1.ENMO_t_mean = c(0.0239268821264327, 0.0237063614378219,
0.0237014797190142, 0.0239896011495783, 0.0243401417506231),
x2.AI_mean = c(0.294080313622427, 0.477944468152524, 0.260808829802468,
0.456214057286552, 0.84614872784907), x2.MAD_mean = c(0.00263194956522427,
0.00393549027910995, 0.00242397010624937, 0.00473452632379309,
0.00967936115719858), x2.SD_mean = c(0.00620183543213348,
0.00897436349787661, 0.00376656976842411, 0.0102128144373202,
0.026857971881988), x2.ENMO_t_mean = c(0.0152786778953128,
0.0134201176591068, 0.0105504453766938, 0.0126154127095435,
0.0194672090503613), x3.AI_mean = c(0.0735792814229227, 0.0514050450635112,
0.105131723525748, 0.128627572902289, 0.402271889323791),
x3.MAD_mean = c(0.00139436591181368, 0.000712147674432812,
0.00119105634569394, 0.00119348650394604, 0.00356665669204264
), x3.SD_mean = c(0.00199624824940588, 0.00120092927705721,
0.00193145315212752, 0.0019283335835232, 0.00656874765265735
), x3.ENMO_t_mean = c(0.0139865818700652, 0.0139851935882149,
0.0139915889947178, 0.01398633901765, 0.0144706584272194),
x4.AI_mean = c(0.0156678651943813, 0.0486531274165618, 0.033482857018396,
0.0377258494079243, 0.0678175492814511), x4.MAD_mean = c(0.000251120428854605,
0.000562880039987649, 0.000528793978359871, 0.00124991974998928,
0.000757489838974229), x4.SD_mean = c(0.000533766751727111,
0.00134959539056406, 0.000857977081466285, 0.00213180063264727,
0.00127973763932144), x4.ENMO_t_mean = c(0.0207155829098077,
0.020761171880961, 0.0207540203103165, 0.0202677052046802,
0.0198891636700763), x5.AI_mean = c(0.117604774640621, 0.0670305430061501,
0.0341376355863943, 0.13364297618809, 0.306972659040445),
x5.MAD_mean = c(0.0014759342409207, 0.000989910934380608,
0.000403358793801372, 0.00146211525459881, 0.00279101071524453
), x5.SD_mean = c(0.00332215932515048, 0.00195612286464375,
0.00100728633289468, 0.00269074473283573, 0.00460104621279968
), x5.ENMO_t_mean = c(0.0154521138471442, 0.0154613646883262,
0.0154478187295753, 0.0157331526286594, 0.0158523807067694
), x6.AI_mean = c(0.100509771506111, 0.0758254065303984,
0.116304451335499, 0.128055772822219, 0.121857857811461),
x6.MAD_mean = c(0.000820743353091489, 0.000853723738604472,
0.00106905689779995, 0.00125348246046243, 0.00132633070226373
), x6.SD_mean = c(0.00122240006684591, 0.00122098986196308,
0.00200131128161969, 0.00174469241955932, 0.00180918568232773
), x6.ENMO_t_mean = c(0.0105689413754299, 0.0104679319373477,
0.0106510201902777, 0.0105852542321717, 0.0110441830680727
), x7.AI_mean = c(0.0286478750449268, 0.0515922904718244,
0.0711332148199368, 0.05020475938917, 0.0830762493042348),
x7.MAD_mean = c(0.000363376272209463, 0.000480238540942994,
0.000628916162718124, 0.000594606941057317, 0.000878481811277494
), x7.SD_mean = c(0.000583562490557928, 0.000759472323982701,
0.00117176811747496, 0.00112513562674996, 0.00137098279570074
), x7.ENMO_t_mean = c(0.0179026688120152, 0.0178767746038774,
0.0174193867673969, 0.0172732431081777, 0.0173507218269879
)), row.names = c(NA, 5L), class = "data.frame")

Re-organizing nested list elements in R

I have a long list that has elements including charactor and numeric vectors. I want to re-organize them to the data frame format.
Let's say this is the structure of two first elements of the list_a:
list_a <- list(ENSG00000040608 = list(var = c("chr22_20230714_G_A_b38",
"chr22_20230737_G_A_b38", "chr22_20231229_T_A_b38", "chr22_20231474_G_A_b38",
"chr22_20231667_C_G_b38", "chr22_20231957_G_C_b38", "chr22_20231969_G_T_b38",
"chr22_20232125_G_A_b38", "chr22_20232392_G_A_b38", "chr22_20232643_A_C_b38"
), coeff = c(0.0000953181301665087, -0.00124036704551427, 0.000808061558738542,
0.000387528601423933, -0.000120624028990859, -0.00119982510044018,
-0.000120623899338185, -0.000435011907222715, 0.000715410285903684,
-0.000347899088267475)), ENSG00000040608 = list(var = c("chr22_20230714_G_A_b38",
"chr22_20230737_G_A_b38", "chr22_20231229_T_A_b38", "chr22_20231474_G_A_b38",
"chr22_20231667_C_G_b38", "chr22_20231957_G_C_b38", "chr22_20231969_G_T_b38",
"chr22_20232125_G_A_b38", "chr22_20232392_G_A_b38", "chr22_20232643_A_C_b38"
), coeff = c(0.0000953181301665087, -0.00124036704551427, 0.000808061558738542,
0.000387528601423933, -0.000120624028990859, -0.00119982510044018,
-0.000120623899338185, -0.000435011907222715, 0.000715410285903684,
-0.000347899088267475)))
The desire output as list_b:
list_b <- list(ENSG00000040608 = structure(list(chr22_20230714_G_A_b38 = -0.000347899088267475,
chr22_20230737_G_A_b38 = 0.0000953181301665087, chr22_20231229_T_A_b38 = -0.00124036704551427,
chr22_20231474_G_A_b38 = 0.000808061558738542, chr22_20231667_C_G_b38 = 0.000387528601423933,
chr22_20231957_G_C_b38 = -0.000120624028990859, chr22_20231969_G_T_b38 = -0.00119982510044018,
chr22_20232125_G_A_b38 = -0.000120623899338185, chr22_20232392_G_A_b38 = -0.000435011907222715,
chr22_20232643_A_C_b38 = -0.000347899088267475), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame")), ENSG00000040608 = structure(list(
chr22_20230714_G_A_b38 = -0.000347899088267475, chr22_20230737_G_A_b38 = 0.0000953181301665087,
chr22_20231229_T_A_b38 = -0.00124036704551427, chr22_20231474_G_A_b38 = 0.000808061558738542,
chr22_20231667_C_G_b38 = 0.000387528601423933, chr22_20231957_G_C_b38 = -0.000120624028990859,
chr22_20231969_G_T_b38 = -0.00119982510044018, chr22_20232125_G_A_b38 = -0.000120623899338185,
chr22_20232392_G_A_b38 = -0.000435011907222715, chr22_20232643_A_C_b38 = -0.000347899088267475), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame")))
Also I need to have those numbers as integer.
I would appreciate your guidance.
base R
lapply(list_a, function(x) {
df <- as.data.frame(t(x[[2]]))
colnames(df) <- x[[1]]
df
})
tidyverse
library(tidyverse)
map(list_a, ~ .x %>%
as_tibble() %>%
pivot_wider(names_from = "var", values_from = "coeff"))

values become NA after use left_join() function in r

The value in another data frame becomes NA after I used left_join() function. And I check the answer at here[dplyr::left_join produce NA values for new joined columns.
I also specify the by arguement but failed.
I don't know why.
qx_p2 <- structure(list(province = c("安徽", "安徽", "安徽", "安徽", "安徽"
), date = c("2020-01-21", "2020-01-22", "2020-01-23", "2020-01-24",
"2020-01-25"), PRS = c(1013.9035387141, 1011.48779584751, 1014.28302402211,
1019.16970261716, 1018.92203467498), PRS_Sea = c(1024.73084750567,
1022.22210612717, 1025.02632842026, 1029.97905104403, 1029.77650132275
), PRS_Max = c(1014.26828869048, 1011.80445613662, 1014.51628117914,
1019.43671957672, 1019.31935504063), PRS_Min = c(1013.7138513322,
1011.13447054516, 1013.86811271731, 1018.75406934996, 1018.62469257842
), WIN_S_Max = c(2.30187606292517, 2.08586132369615, 2.76893908257748,
4.22074853552532, 3.63427225056689), WIN_S_Inst_Max = c(3.44360343442933,
3.09963836923658, 4.28499952758881, 6.68930898053666, 5.80619165721844
), WIN_D_INST_Max = c(116.878029336735, 218.745851048753, 120.88310303288,
72.1640447845805, 72.0331526360544), WIN_D_Avg_2mi = c(116.23329724764,
210.524530689871, 113.104009452075, 68.7694017991261, 70.322008604388
), WIN_S_Avg_2mi = c(1.77558118386243, 1.49959490740741, 2.20936874055178,
3.47942613851096, 2.99431642101285), WIN_D_S_Max = c(116.68018866665,
218.180671371681, 120.40502999811, 71.0831467309146, 68.3670670351474
), TEM = c(3.81968088624339, 5.16464226662887, 6.82721856103553,
5.98099596088435, 4.8940626181028), TEM_Max = c(4.04776301492819,
5.35075514928193, 6.97597470238095, 6.15192401266062, 5.07960293839758
), TEM_Min = c(3.49020455404384, 4.95346053004535, 6.65049142573696,
5.85618067365835, 4.76455794123205), RHU = c(85.9359859221466,
96.1710766250945, 91.749678760393, 88.3347741874528, 80.693040202192
), VAP = c(6.98015376984127, 8.55406509826153, 9.08114866780046,
8.27843124055178, 6.98599714191232), RHU_Min = c(83.965092356387,
95.6411387471655, 90.9997401738473, 87.3134436413454, 79.2219635770975
), PRE_1h = c(0.102133763227513, 0.422205333522298, 1488.33246492347,
0.0715384070294785, 372.116791028911)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -5L))
covid_p2 <- structure(list(province = c("安徽", "安徽", "安徽", "安徽", "安徽"
), date = c("2020/1/21", "2020/1/22", "2020/1/23", "2020/1/24",
"2020/1/25"), 新增确诊 = c(0L, 1L, 14L, 24L, 21L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -5L))
dat2 <- covid_p2 %>% left_join(qx_p2, by = c('province' = 'province', 'date' = 'date'))
dat2
Your date columns are character columns and do not have the same format:
qx_p2$date
# "2020-01-21" "2020-01-22" "2020-01-23" "2020-01-24" "2020-01-25"
covid_p2$date
# "2020/1/21" "2020/1/22" "2020/1/23" "2020/1/24" "2020/1/25"
You can get them in the same format by, for example, applying as.Date(...):
covid_p2$date <- as.Date(covid_p2$date)
qx_p2$date <- as.Date(qx_p2$date)
After that, your join works.

R reading data from Elastic

I am reading some records from Elastic into R and it is turning out to be painfully slow.
Context - The data is for a property marketplace. The table I am reading is for property views (i.e. when someone clicks on a property to see details). I need to capture property ID and view date & time for analytics.
This is what I am doing:
Extract the data from Elastic into a list
query <- sprintf('{"query":{"range":{"time":{"gte":"%s","lte":"%s"}}}}',start_date,end_date)
view_list <- elastic::Search(index = "organised",type = "PROPERTY_VIEW",size = 10000000,body=query)$hits$hits
Extract the list into fields in a data frame
number_of_views <- length(view_list)
a <- 1
view_data <- data.frame(view_date=as.Date(character()),
propertyId=character())
view_date = vector(mode = "character",length = 0)
propertyId = vector(mode = "character",length = 0)
while (a <= number_of_views) {
view_date[a] <- as.Date(as.POSIXct(view_list[[a]][[6]]$time/1000, origin="1970-01-01"))
propertyId <- as.character(view_list[[a]][[6]]$propertyId)
a <- a+1
}
view_list_df <- data.frame(trackId,userId,viewId,view_date,requestId,propertyId)
Speed - To read 1 week's of data (500k records) is taking 7-8 minutes. this is just too slow.
list sample:
> head(dput(view_list[1:10]))
list(structure(list(`_index` = "organised", `_type` = "PROPERTY_VIEW",
`_id` = "ff8081814ea04efe014ea6843b7f3d13:ff8081814e5cc5af014e5ce7dff202a9",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "8e370fe75121cda0cccda2f1934c7051", userId = "ff8081814ea04efe014ea6843b7f3d13",
id = "ff8081814ea04efe014ea6843b7f3d13:ff8081814e5cc5af014e5ce7dff202a9",
time = 1437351878754, requestId = "1437351878754", propertyId = "ff8081814e5cc5af014e5ce7dff202a9"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "6b2eaf11c2e4ba6be7c3bd109d8905aa:ff8081814d5bcfaa014d62b622352d78",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "6b2eaf11c2e4ba6be7c3bd109d8905aa", userId = NULL,
id = "6b2eaf11c2e4ba6be7c3bd109d8905aa:ff8081814d5bcfaa014d62b622352d78",
time = 1437351694070, requestId = "1437351694070", propertyId = "ff8081814d5bcfaa014d62b622352d78"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "84879c86112f53f1124a1f9cb83d6b37:ff8081814d28f714014d31eb92a2210b",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "84879c86112f53f1124a1f9cb83d6b37", userId = NULL,
id = "84879c86112f53f1124a1f9cb83d6b37:ff8081814d28f714014d31eb92a2210b",
time = 1437351931929, requestId = "1437351931929", propertyId = "ff8081814d28f714014d31eb92a2210b"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "84879c86112f53f1124a1f9cb83d6b37:ff8081814ca1cc06014ca2b9823c0571",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "84879c86112f53f1124a1f9cb83d6b37", userId = NULL,
id = "84879c86112f53f1124a1f9cb83d6b37:ff8081814ca1cc06014ca2b9823c0571",
time = 1437351964188, requestId = "1437351964188", propertyId = "ff8081814ca1cc06014ca2b9823c0571"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "38212cb8dbd60c10d356fe30257932b4:ff8081814d42cfff014d473b7f071161",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "38212cb8dbd60c10d356fe30257932b4", userId = NULL,
id = "38212cb8dbd60c10d356fe30257932b4:ff8081814d42cfff014d473b7f071161",
time = 1437353794879, requestId = "1437353794879", propertyId = "ff8081814d42cfff014d473b7f071161"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "ff8081814ea04efe014ea6843b7f3d13:ff8081814d891540014d8eac50142535",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "91bbfe57428a47ce2233da1b5517b9a1", userId = "ff8081814ea04efe014ea6843b7f3d13",
id = "ff8081814ea04efe014ea6843b7f3d13:ff8081814d891540014d8eac50142535",
time = 1437353798036, requestId = "1437353798036", propertyId = "ff8081814d891540014d8eac50142535"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "830f0fe6d53c58938d876175ceca357c:ff8081814e71b801014e72a340300b74",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "830f0fe6d53c58938d876175ceca357c", userId = NULL,
id = "830f0fe6d53c58938d876175ceca357c:ff8081814e71b801014e72a340300b74",
time = 1437355401546, requestId = "1437355401546", propertyId = "ff8081814e71b801014e72a340300b74"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "88200b3e1bc22cb4b270f89810cd8f32:ff8081814db00698014db29fb80d0614",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "88200b3e1bc22cb4b270f89810cd8f32", userId = NULL,
id = "88200b3e1bc22cb4b270f89810cd8f32:ff8081814db00698014db29fb80d0614",
time = 1437355324426, requestId = "1437355324426", propertyId = "ff8081814db00698014db29fb80d0614"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "2e9afe62406bedbf90d14fd22a6296de:ff80808149f1ccdc0149f4dd916500e2",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "2e9afe62406bedbf90d14fd22a6296de", userId = NULL,
id = "2e9afe62406bedbf90d14fd22a6296de:ff80808149f1ccdc0149f4dd916500e2",
time = 1437355340320, requestId = "1437355340320", propertyId = "ff80808149f1ccdc0149f4dd916500e2"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")), structure(list(
`_index` = "organised", `_type` = "PROPERTY_VIEW", `_id` = "357c4a9917b47635a6dba600805861f4:ff80808149e225cd0149e2ba48d5009c",
`_version` = 1L, `_score` = 1, `_source` = structure(list(
trackId = "357c4a9917b47635a6dba600805861f4", userId = NULL,
id = "357c4a9917b47635a6dba600805861f4:ff80808149e225cd0149e2ba48d5009c",
time = 1437355340832, requestId = "1437355340832", propertyId = "ff80808149e225cd0149e2ba48d5009c"), .Names = c("trackId",
"userId", "id", "time", "requestId", "propertyId"))), .Names = c("_index",
"_type", "_id", "_version", "_score", "_source")))
[[1]]
[[1]]$`_index`
[1] "organised"
[[1]]$`_type`
[1] "PROPERTY_VIEW"
[[1]]$`_id`
[1] "ff8081814ea04efe014ea6843b7f3d13:ff8081814e5cc5af014e5ce7dff202a9"
[[1]]$`_version`
[1] 1
[[1]]$`_score`
[1] 1
[[1]]$`_source`
[[1]]$`_source`$trackId
[1] "8e370fe75121cda0cccda2f1934c7051"
[[1]]$`_source`$userId
[1] "ff8081814ea04efe014ea6843b7f3d13"
[[1]]$`_source`$id
[1] "ff8081814ea04efe014ea6843b7f3d13:ff8081814e5cc5af014e5ce7dff202a9"
[[1]]$`_source`$time
[1] 1437351878754
[[1]]$`_source`$requestId
[1] "1437351878754"
[[1]]$`_source`$propertyId
[1] "ff8081814e5cc5af014e5ce7dff202a9"
[[2]]
[[2]]$`_index`
[1] "organised"
[[2]]$`_type`
[1] "PROPERTY_VIEW"
[[2]]$`_id`
[1] "6b2eaf11c2e4ba6be7c3bd109d8905aa:ff8081814d5bcfaa014d62b622352d78"
[[2]]$`_version`
[1] 1
[[2]]$`_score`
[1] 1
[[2]]$`_source`
[[2]]$`_source`$trackId
[1] "6b2eaf11c2e4ba6be7c3bd109d8905aa"
[[2]]$`_source`$userId
NULL
[[2]]$`_source`$id
[1] "6b2eaf11c2e4ba6be7c3bd109d8905aa:ff8081814d5bcfaa014d62b622352d78"
[[2]]$`_source`$time
[1] 1437351694070
[[2]]$`_source`$requestId
[1] "1437351694070"
[[2]]$`_source`$propertyId
[1] "ff8081814d5bcfaa014d62b622352d78"
[[3]]
[[3]]$`_index`
[1] "organised"
[[3]]$`_type`
[1] "PROPERTY_VIEW"
[[3]]$`_id`
[1] "84879c86112f53f1124a1f9cb83d6b37:ff8081814d28f714014d31eb92a2210b"
[[3]]$`_version`
[1] 1
[[3]]$`_score`
[1] 1
[[3]]$`_source`
[[3]]$`_source`$trackId
[1] "84879c86112f53f1124a1f9cb83d6b37"
[[3]]$`_source`$userId
NULL
[[3]]$`_source`$id
[1] "84879c86112f53f1124a1f9cb83d6b37:ff8081814d28f714014d31eb92a2210b"
[[3]]$`_source`$time
[1] 1437351931929
[[3]]$`_source`$requestId
[1] "1437351931929"
[[3]]$`_source`$propertyId
[1] "ff8081814d28f714014d31eb92a2210b"
[[4]]
[[4]]$`_index`
[1] "organised"
[[4]]$`_type`
[1] "PROPERTY_VIEW"
[[4]]$`_id`
[1] "84879c86112f53f1124a1f9cb83d6b37:ff8081814ca1cc06014ca2b9823c0571"
[[4]]$`_version`
[1] 1
[[4]]$`_score`
[1] 1
[[4]]$`_source`
[[4]]$`_source`$trackId
[1] "84879c86112f53f1124a1f9cb83d6b37"
[[4]]$`_source`$userId
NULL
[[4]]$`_source`$id
[1] "84879c86112f53f1124a1f9cb83d6b37:ff8081814ca1cc06014ca2b9823c0571"
[[4]]$`_source`$time
[1] 1437351964188
[[4]]$`_source`$requestId
[1] "1437351964188"
[[4]]$`_source`$propertyId
[1] "ff8081814ca1cc06014ca2b9823c0571"
[[5]]
[[5]]$`_index`
[1] "organised"
[[5]]$`_type`
[1] "PROPERTY_VIEW"
[[5]]$`_id`
[1] "38212cb8dbd60c10d356fe30257932b4:ff8081814d42cfff014d473b7f071161"
[[5]]$`_version`
[1] 1
[[5]]$`_score`
[1] 1
[[5]]$`_source`
[[5]]$`_source`$trackId
[1] "38212cb8dbd60c10d356fe30257932b4"
[[5]]$`_source`$userId
NULL
[[5]]$`_source`$id
[1] "38212cb8dbd60c10d356fe30257932b4:ff8081814d42cfff014d473b7f071161"
[[5]]$`_source`$time
[1] 1437353794879
[[5]]$`_source`$requestId
[1] "1437353794879"
[[5]]$`_source`$propertyId
[1] "ff8081814d42cfff014d473b7f071161"
[[6]]
[[6]]$`_index`
[1] "organised"
[[6]]$`_type`
[1] "PROPERTY_VIEW"
[[6]]$`_id`
[1] "ff8081814ea04efe014ea6843b7f3d13:ff8081814d891540014d8eac50142535"
[[6]]$`_version`
[1] 1
[[6]]$`_score`
[1] 1
[[6]]$`_source`
[[6]]$`_source`$trackId
[1] "91bbfe57428a47ce2233da1b5517b9a1"
[[6]]$`_source`$userId
[1] "ff8081814ea04efe014ea6843b7f3d13"
[[6]]$`_source`$id
[1] "ff8081814ea04efe014ea6843b7f3d13:ff8081814d891540014d8eac50142535"
[[6]]$`_source`$time
[1] 1437353798036
[[6]]$`_source`$requestId
[1] "1437353798036"
[[6]]$`_source`$propertyId
[1] "ff8081814d891540014d8eac50142535"

Error in View : undefined columns selected

Below is a subsample of my data set (only 2 rows by 215 columns). I am trying to view them on RStudio but it gives me the following error:
Error in View : undefined columns selected
Do not really know what is going on. The whole set is 7786 rows by 215 columns. Viewing it works fine, however, when doing any kind of subsetting or removing one row it is no longer want to view.
structure(list(`NA` = structure(c(16343, 16344), class = "Date"),
AVON = c("615.5", "621.5"), BA. = c("471.5", "463.2"), CMRG = c("224.5",
"224.5"), COB = c("291.10000000000002", "283.5"), MGGT = c("451.2",
"444.7"), QQ. = c("224.5", "223.5"), RR. = c("953.65", "933.38"
), SNR = c("268.2", "264.7"), ULE = c("1771", "1746"), GKN = c("319.2",
"311.5"), BRAG = c("617", "603"), BVIC = c("668", "661"),
CCH = c("1333", "1327"), DGE = c("1785", "1760.5"), SAB = c("3428",
"3383"), STCK = c("291.60000000000002", "294"), ALNT = c("328",
"321"), CAR = c("125", "124.5"), CRDA = c("2053", "1990"),
ELM = c("255.5", "254.5"), JMAT = c("2919", "2825"), SYNT = c("212",
"210.8"), VCTA = c("1606", "1605"), DIA = c("901", "924"),
DNO = c("611", "611"), E2V = c("161", "160.5"), HLMA = c("612",
"598.5"), HTY = c("309.8", "308"), MGAM = c("296.8", "289.40000000000003"
), OXFD = c("1020", "1035"), RSHW = c("1630", "1625"), SXS = c("1808",
"1778"), TTG = c("166.75", "167.5"), XAR = c("376", "367"
), X = c("1527", "1520"), ABF = c("2679", "2654"), AE = c("633.5",
"640"), CARM = c("1647", "1637"), CWK = c("1328", "1320"),
DCG = c("383.75", "369"), DVO = c("237.75", "231"), GNCL = c("234",
"229.6"), HFG = c("416", "411"), FD = c("36.5", "34.75"),
TATE = c("591.5", "585"), MNDI = c("1011", "1012"), BI = c("616",
"620"), REX = c("491.8", "483.5"), RC = c("559", "540"),
SMDS = c("266.3", "257"), SMIN = c("1264", "1250"), VSVS = c("451.8",
"438.40000000000003"), AGA = c("163.25", "160.25"), BDEV = c("396.1",
"389.3"), BKG = c("2250", "2224"), BLWY = c("1567", "1558"
), BVS = c("779", "771"), CRST = c("325", "314.60000000000002"
), GLSN = c("393.5", "388.5"), MCB = c("83.53", "83.29"),
SN = c("1334", "1309"), RB. = c("5350", "5305"), RDW = c("280.7",
"273.8"), TW. = c("112.8", "111.8"), BODY = c("668.5", "647"
), FENR = c("317.60000000000002", "313.10000000000002"),
GDWN = c("3500", "3500"), HILS = c("561", "561.5"), IMI = c("1230",
"1206"), MRO = c("247.70000000000002", "246"), VAR = c("304",
"300.75"), RNO = c("56", "54.5"), RTRK = c("2765", "2736"
), SFR = c("63.5", "64"), SRX = c("2826", "2812"), TRI = c("105.75",
"105"), VTC = c("613.5", "612"), WEIR = c("2502", "2430"),
EVR = c("130", "123.60000000000001"), FXO = c("112.3", "105.10000000000001"
), BBA = c("325", "326"), BMS = c("494.38", "492"), CKN = c("2350",
"2341"), FSHR = c("1326", "1294"), RMG = c("392.2", "399.7"
), STOB = c("111", "109"), UKM = c("473.88", "467"), WIN = c("136.25",
"137.5"), GAW = c("597.5", "585"), HTM = c("131.5", "129.25"
), `NA` = c(NA_character_, NA_character_), AAL = c("1384",
"1363.5"), ABG = c("218.8", "209.1"), ANTO = c("721", "702"
), AF = c("131.5", "130.25"), AQ = c("18.5", "18.75"), ARMS = c("69",
"62.25"), BLT = c("1715", "1690.5"), CEY = c("61.15", "61"
), FRES = c("760", "747"), GEMD = c("192", "191.75"), GLEN = c("343.2",
"336.45"), HOC = c("135.30000000000001", "130.19999999999999"
), KAZ = c("263.39999999999998", "260.10000000000002"), KMRL = c("9.5",
"9.3000000000000007"), LMI = c("185.8", "176.8"), NWR = c("1.97",
"1.82"), `NA` = c(NA_character_, NA_character_), DL = c("190.20000000000002",
"190"), OG = c("22", "24"), OLY = c("516", "496.6"), RIO = c("3031.5",
"3020"), RRS = c("4209", "4154"), VED = c("998.5", "974.5"
), AFR = c("103.5", "109.4"), BG. = c("1140", "1093"), B. = c("453.45",
"452.75"), CNE = c("176.5", "171.6"), ENQ = c("109.60000000000001",
"107.8"), EXI = c("157", "150"), HDY = c("102", "99.75"),
JKX = c("48.25", "47"), OHR = c("229.3", "220.9"), MO = c("333",
"324.7"), RDSA = c("2358.5", "2331"), RDSB = c("2437", "2418.5"
), SIA = c("381", "377.90000000000003"), SMDR = c("100",
"98.5"), TLW = c("644.5", "631"), AMEC = c("1104", "1077"
), CIU = c("283.5", "275.75"), GMS = c("157", "157"), HTG = c("892.5",
"876"), LAM = c("163.25", "160"), FC = c("1037", "1011"),
WG. = c("759.5", "743"), BRBY = c("1511", "1476"), ZC = c("365.7",
"366"), SG = c("1133", "1126"), TED = c("1863", "1862"),
ULVR = c("2585", "2547"), AZN = c("4441.5", "4360.5"), BTG = c("700",
"697.5"), CIR = c("304", "300"), DH = c("758", "753"), GNS = c("1130",
"1130"), GSK = c("1413", "1414"), HIK = c("1733", "1715"),
SH = c("5340", "5310"), SK = c("329.25", "319"), VEC = c("132",
"132"), AGK = c("1548", "1528"), AHT = c("1043", "1024"),
ATK = c("1317", "1323"), BAB = c("1092", "1085"), BNZL = c("1610",
"1597"), BRAM = c("376", "374"), BRSN = c("980", "979"),
CLLN = c("304.60000000000002", "304.3"), CMS = c("59.75",
"59.5"), CNCT = c("149.25", "151"), CI = c("1164", "1165"
), CTR = c("259.5", "255"), DCC = c("3422", "3405"), DLAR = c("477",
"478"), DLM = c("689.5", "685"), ECOM = c("223", "219.8"),
ESNT = c("797.5", "792.5"), EXO = c("176.5", "180"), EXN = c("983.5",
"968"), GFS = c("250.70000000000002", "251.6"), GFTU = c("626",
"616"), HAS = c("116.3", "115.7"), HRG = c("45.75", "45.75"
), HSV = c("319.7", "319"), HWDN = c("339.1", "335"), HYC = c("749",
"748"), IRV = c("599.5", "592.5"), ITRK = c("2621", "2631"
), LVD = c("201.75", "201.5"), MER = c("435", "436.75"),
MMC = c("25.25", "25"), MNZS = c("569", "575.5"), MI = c("418.6",
"421"), MTO = c("287.90000000000003", "286.60000000000002"
), NTG = c("483.8", "481.3"), AY = c("983.5", "989"), FL = c("182",
"180.1"), RCDO = c("671", "667.5"), RENT = c("117.8", "116"
), RGU = c("169.70000000000002", "169.9"), RS = c("261",
"251.6"), RWA = c("302.5", "302.5"), SDY = c("70.5", "69.75"
), SERC = c("286.10000000000002", "279.8"), SHI = c("166.6",
"161.1"), SIV = c("199.75", "200"), SKS = c("90", "92"),
STHR = c("350.25", "358.5"), TK = c("1664", "1635"), TRB = c("170.5",
"172"), V. = c("609.5", "600"), WOS = c("3242", "3243"),
XCH = c("188", "184.75"), ARM = c("906", "887.5"), BVC = c("16.38",
"16.25"), CSR = c("758", "756"), IMG = c("188.5", "184.75"
), LRD = c("309.7", "306.7"), IC = c("298.10000000000002",
"299"), SEU = c("141", "141"), ST = c("104.60000000000001",
"99.9"), BATS = c("3482", "3480"), IMT = c("2664", "2679"
)), .Names = c("NA", "AVON", "BA.", "CMRG", "COB", "MGGT",
"QQ.", "RR.", "SNR", "ULE", "GKN", "BRAG", "BVIC", "CCH", "DGE",
"SAB", "STCK", "ALNT", "CAR", "CRDA", "ELM", "JMAT", "SYNT",
"VCTA", "DIA", "DNO", "E2V", "HLMA", "HTY", "MGAM", "OXFD", "RSHW",
"SXS", "TTG", "XAR", "X", "ABF", "AE", "CARM", "CWK", "DCG",
"DVO", "GNCL", "HFG", "FD", "TATE", "MNDI", "BI", "REX", "RC",
"SMDS", "SMIN", "VSVS", "AGA", "BDEV", "BKG", "BLWY", "BVS",
"CRST", "GLSN", "MCB", "SN", "RB.", "RDW", "TW.", "BODY", "FENR",
"GDWN", "HILS", "IMI", "MRO", "VAR", "RNO", "RTRK", "SFR", "SRX",
"TRI", "VTC", "WEIR", "EVR", "FXO", "BBA", "BMS", "CKN", "FSHR",
"RMG", "STOB", "UKM", "WIN", "GAW", "HTM", NA, "AAL", "ABG",
"ANTO", "AF", "AQ", "ARMS", "BLT", "CEY", "FRES", "GEMD", "GLEN",
"HOC", "KAZ", "KMRL", "LMI", "NWR", NA, "DL", "OG", "OLY", "RIO",
"RRS", "VED", "AFR", "BG.", "B.", "CNE", "ENQ", "EXI", "HDY",
"JKX", "OHR", "MO", "RDSA", "RDSB", "SIA", "SMDR", "TLW", "AMEC",
"CIU", "GMS", "HTG", "LAM", "FC", "WG.", "BRBY", "ZC", "SG",
"TED", "ULVR", "AZN", "BTG", "CIR", "DH", "GNS", "GSK", "HIK",
"SH", "SK", "VEC", "AGK", "AHT", "ATK", "BAB", "BNZL", "BRAM",
"BRSN", "CLLN", "CMS", "CNCT", "CI", "CTR", "DCC", "DLAR", "DLM",
"ECOM", "ESNT", "EXO", "EXN", "GFS", "GFTU", "HAS", "HRG", "HSV",
"HWDN", "HYC", "IRV", "ITRK", "LVD", "MER", "MMC", "MNZS", "MI",
"MTO", "NTG", "AY", "FL", "RCDO", "RENT", "RGU", "RS", "RWA",
"SDY", "SERC", "SHI", "SIV", "SKS", "STHR", "TK", "TRB", "V.",
"WOS", "XCH", "ARM", "BVC", "CSR", "IMG", "LRD", "IC", "SEU",
"ST", "BATS", "IMT"), row.names = 7785:7786, class = "data.frame")
I am on Mac OS 10.10, R 3.1.1 and RStudio 0.98.1060.
One of your column names is NA. If d is your data defined above, then try names(d)[92]. Try replacing with a non-missing column name.
As allready mentioned by DMC, but with a short version of your example code.
a <- structure(list(`NA` = structure(c(16343, 16344), class = "Date"),
AVON = c("615.5", "621.5"),
BA. = c("471.5", "463.2"),
`NA` = c(NA_character_, NA_character_), AAL = c("1384", "1363.5")),
.Names = c(NA, "AVON", "BA.", "NA", "AAL"), row.names = 7785:7786, class = "data.frame")
View(a)
Error in View : undefined columns selected
names(a)
[1] NA "AVON" "BA." "NA" "AAL"
a <- structure(list(`NA` = structure(c(16343, 16344), class = "Date"),
AVON = c("615.5", "621.5"),
BA. = c("471.5", "463.2"),
`NA` = c(NA_character_, NA_character_), AAL = c("1384", "1363.5")),
.Names = c("NA", "AVON", "BA.", "NA", "AAL"), row.names = 7785:7786, class = "data.frame")
View(a)
names(a)
[1] "NA" "AVON" "BA." "NA" "AAL"
You need to have proper names in the data frame to View it.

Resources