我试图将一些列表列表作为数据框,并在每个步骤中保留列表名称。预期的输出将类似于以下内容:
预期输出:
# A tibble: 20 x 29
NAME NAME2 protocol_active wind holiday month_10 month_8 temp month_11 humidity weekday month_1 text_scattered_~
1 myname1 list_of_list_1 0.477 0.422 0.238 0.174 0.146 0.136 0.117 0.0981 0.0936 0.0758 0.0714
2 myname1 list_of_list_2 0.428 0.409 0.0866 0.0551 0.143 0.138 0.275 0.0898 0.131 0.0596 0.0490
3 myname1 list_of_list_3 0.00647 0.337 0.199 0.144 0.0588 0.144 0.137 0.0828 0.0824 0.192 0.101
4 myname1 list_of_list_4 0.457 0.387 0.166 0.0699 0.0830 0.149 0.272 0.0930 0.106 0.0928 0.0523
5 myname1 list_of_list_5 0.0535 0.286 0.155 0.150 0.0472 0.135 0.164 0.0645 0.0990 0.180 0.0775
6 myname1 list_of_list_6 0.0420 0.328 0.161 0.114 0.0438 0.122 0.130 0.0605 0.0832 0.175 0.123
7 myname1 list_of_list_7 0 0.318 0.185 0.133 0.0488 0.136 0.192 0.0683 0.0752 0.0980 0.0996
8 myname1 list_of_list_8 0.515 0.369 0.185 0.0513 0.112 0.149 0.235 0.0832 0.136 0.0524 0.0450
我将列表名称作为新列。我当前使用的代码是:
代码:
library(dplyr)
library(purrr)
mylist_of_list_names <- sprintf("list_of_list_%s",seq(1:10))
NamedList <- myList %>% # I create some list names
setNames(c("myname1", "myname2")) %>%
map(., ~setNames(., c(mylist_of_list_names)))
Final_List <- NamedList %>%
map_dfr(., ~map_dfr(.x, as.list))
但是,当我尝试使用以下方法修改Final_List
时:
Final_List <- NamedList %>%
map_dfr(., .id = names(.), ~map_dfr(.x, as.list, .id = names(.)))
我似乎无法存储列表名称。我试图在每个.id
函数的包文档here中添加map_dfr
对象。
数据:
myList <- list(list(c(protocol_active = 0.476690486794737, wind = 0.421644905580702,
holiday = 0.237855180468597, month_10 = 0.174138672609035, month_8 = 0.146189977753241,
temp = 0.136091939119292, month_11 = 0.117059004222591, humidity = 0.0981068528147208,
weekday = 0.0936421424983979, month_1 = 0.075759335979394, text_scattered_clouds = 0.0714021764373941,
month_4 = 0.0458588632888939, month_3 = 0.044565083971885, month_12 = 0.0400631134202661,
month_7 = 0.0396780361927733, month_9 = 0.0313980546969172, month_6 = 0.0307021354848187,
barometer = 0.0297905815436382, month_5 = 0.0275607431560466,
text_light_rain = 0.0165770194829191, month_2 = 0.0165630157979537,
text_mostly_cloudy = 0.0121088618908841, text_sunny = 0.00941388986252044,
text_fog = 0.00924611477602324, workday_on_holiday = 0.00284118722006891,
text_passing_clouds = 0.00150433375272096, text_rain = 0.00131183594715628,
weekend = 0, weekend_on_holiday = 0), c(protocol_active = 0.427757390802854,
wind = 0.408503171009464, month_11 = 0.275057127435594, month_8 = 0.142977205336468,
temp = 0.138475854744559, weekday = 0.131070281010648, humidity = 0.0898046759674304,
holiday = 0.086630490993674, month_1 = 0.0596217489313094, month_10 = 0.0551334046364746,
text_scattered_clouds = 0.0490242183124676, month_12 = 0.045106370859385,
month_4 = 0.0419702477855225, month_3 = 0.0404903265753906, month_5 = 0.0359349426154136,
barometer = 0.035618224264753, month_6 = 0.0338249178101483,
month_7 = 0.0327099416366689, month_9 = 0.0293428124958271, text_mostly_cloudy = 0.0270874829871817,
month_2 = 0.0180123197586705, text_passing_clouds = 0.0118664281453393,
text_sunny = 0.0103031663280448, text_light_rain = 0.00942806139275789,
text_fog = 0.00806600748408229, workday_on_holiday = 0.00241487503942681,
text_rain = 0.0000570347965499609, weekend = 0, weekend_on_holiday = 0
), c(wind = 0.336572349791158, holiday = 0.198779253833438, month_1 = 0.192421516318504,
month_10 = 0.144445315616197, temp = 0.143690255193945, month_11 = 0.137325167540274,
text_scattered_clouds = 0.10122916446616, humidity = 0.0828318548018303,
weekday = 0.0823615530607839, month_12 = 0.0737718595642614,
month_5 = 0.0594576071260418, month_8 = 0.0588273438617596, month_4 = 0.0573095170966537,
text_mostly_cloudy = 0.0480329543671073, month_6 = 0.0402532857184651,
barometer = 0.0396320005493679, month_3 = 0.026472471467845,
month_7 = 0.0262888669729505, month_9 = 0.0259344946067317, text_sunny = 0.0131106700559495,
month_2 = 0.012995547924582, workday_on_holiday = 0.00982112260492833,
text_passing_clouds = 0.00683627593864011, protocol_active = 0.00647374322450801,
text_light_rain = 0.0063248456805146, text_fog = 0.00585607353395349,
text_rain = 0.000405401311389258, weekend = 0, weekend_on_holiday = 0
), c(protocol_active = 0.457218040022404, wind = 0.386653192913039,
month_11 = 0.271520132187022, holiday = 0.166075296710207, temp = 0.148792881213105,
weekday = 0.106041161955832, humidity = 0.0929848531838744, month_1 = 0.0928483740915651,
month_8 = 0.0829540333434191, month_10 = 0.0699121444845427,
text_fog = 0.0525342428581534, text_scattered_clouds = 0.0522970455826638,
barometer = 0.0431168167702891, month_7 = 0.0419820798871418,
month_4 = 0.041477494010643, month_9 = 0.0375248375546493, month_5 = 0.0354565058054496,
text_mostly_cloudy = 0.0297605077110945, text_passing_clouds = 0.027437090518306,
month_2 = 0.0271775084449888, month_6 = 0.0217419101984227, text_light_rain = 0.0200993262652359,
workday_on_holiday = 0.019565240559317, month_3 = 0.0187113693519814,
month_12 = 0.018413791610736, text_sunny = 0.0099830383163256,
text_rain = 0.00329234272052351, weekend = 0, weekend_on_holiday = 0
), c(wind = 0.285756555215212, month_1 = 0.179849187294914, month_11 = 0.164289483281711,
holiday = 0.154516151695423, month_10 = 0.150120774452196, temp = 0.134707708686716,
weekday = 0.0989596352406424, month_12 = 0.0891791624140386,
text_scattered_clouds = 0.0775458226511579, humidity = 0.0644600094005282,
month_4 = 0.054180913826995, protocol_active = 0.0535038970887117,
month_5 = 0.0524276994044104, text_mostly_cloudy = 0.0474800352970501,
month_6 = 0.0472995256777581, month_8 = 0.047177053618853, barometer = 0.035944823214537,
month_7 = 0.0337175876492492, month_9 = 0.0313097306311111, workday_on_holiday = 0.0255306703510554,
month_3 = 0.0207022198390048, month_2 = 0.0162812998382264, text_sunny = 0.0105475327224613,
text_passing_clouds = 0.00751715134937259, text_light_rain = 0.00611453089628769,
text_fog = 0.00589259659924484, text_rain = 0.00199902163654753,
weekend = 0, weekend_on_holiday = 0), c(wind = 0.328219459502805,
month_1 = 0.175075058064096, holiday = 0.160793264354813, month_11 = 0.129548105560073,
text_scattered_clouds = 0.123147537680045, temp = 0.121607173813749,
month_10 = 0.113682198084755, month_12 = 0.0997093907485133,
weekday = 0.0832095032532329, month_5 = 0.0608440197523202, humidity = 0.060535465962531,
month_4 = 0.0584286914194283, month_9 = 0.0447241908785585, barometer = 0.0440128902307778,
month_8 = 0.0438292939943096, protocol_active = 0.0419578197714128,
month_3 = 0.0339254215996517, month_6 = 0.0337754882748779, month_7 = 0.031814906735976,
month_2 = 0.0270908407671335, text_mostly_cloudy = 0.0219086588144549,
text_sunny = 0.0136285604898165, workday_on_holiday = 0.00761672222267062,
text_light_rain = 0.00634132165607431, text_fog = 0.00608799696248636,
text_passing_clouds = 0.0040204867146501, text_rain = 0.000376092383049835,
weekend = 0, weekend_on_holiday = 0), c(wind = 0.317822839842299,
month_11 = 0.19192646205017, holiday = 0.185426564412574, temp = 0.13593219239286,
month_10 = 0.13277574966079, text_scattered_clouds = 0.0995925773904748,
month_1 = 0.0979915406435864, weekday = 0.0751849300079218, humidity = 0.0683413140459836,
month_2 = 0.0640093204816251, month_5 = 0.0611092551132147, month_7 = 0.058891413580269,
month_6 = 0.0547705294287946, barometer = 0.0514254934314588,
month_8 = 0.0488036307320211, text_mostly_cloudy = 0.0412003813198763,
month_12 = 0.0411461956492842, month_9 = 0.0286932268469131,
month_4 = 0.0229876443679717, month_3 = 0.0189662051480523, workday_on_holiday = 0.0112685893702674,
text_light_rain = 0.0109155125639584, text_passing_clouds = 0.00886646494182724,
text_fog = 0.00528032941976031, text_rain = 0.00421637095753226,
text_sunny = 0.00182733590607928, weekend = 0, weekend_on_holiday = 0,
protocol_active = 0), c(protocol_active = 0.51500155823688, wind = 0.369391322961783,
month_11 = 0.234622367311558, holiday = 0.184593894040067, temp = 0.149243922588351,
weekday = 0.13568649568242, month_8 = 0.111535093753458, humidity = 0.0831650037468867,
month_4 = 0.06233952671686, month_5 = 0.0582210814027481, month_1 = 0.0524249054181079,
month_10 = 0.0513109900081503, text_scattered_clouds = 0.0449822947458677,
month_6 = 0.0371093226111915, month_7 = 0.0345599941131351, barometer = 0.0306446007250308,
month_9 = 0.0274106106748507, text_fog = 0.0221568992510268,
text_passing_clouds = 0.0211599513636558, text_mostly_cloudy = 0.0148391773192782,
month_3 = 0.0141197551543251, month_2 = 0.0140401629120377, workday_on_holiday = 0.00737117942694796,
text_sunny = 0.00720100269873624, month_12 = 0.00527240881870701,
text_light_rain = 0.00130866158585655, text_rain = 0.000624886909196766,
weekend = 0, weekend_on_holiday = 0), c(protocol_active = 0.5812855848983,
wind = 0.388742283293946, month_11 = 0.244592963846307, holiday = 0.158002529973717,
weekday = 0.122634703648961, temp = 0.119940003635667, month_1 = 0.0838425453701248,
month_8 = 0.0770040860945533, humidity = 0.0738192673487, month_10 = 0.0610040306320975,
text_scattered_clouds = 0.0591100941672092, barometer = 0.056244713686979,
month_5 = 0.0369698544273875, month_9 = 0.036858099182753, month_2 = 0.0310369344611044,
month_6 = 0.0301084762225969, month_4 = 0.0287642538258338, text_mostly_cloudy = 0.0273765916021787,
month_3 = 0.025851829004895, month_7 = 0.0254969442110151, text_light_rain = 0.0250549811478619,
text_fog = 0.0222954459465601, workday_on_holiday = 0.0213043972641468,
text_passing_clouds = 0.0177354853346569, month_12 = 0.00949038839605307,
text_sunny = 0.00446652838284589, weekend = 0, weekend_on_holiday = 0,
text_rain = 0), c(protocol_active = 0.474242671289945, wind = 0.422109119973802,
month_10 = 0.18775162510744, holiday = 0.182591428049759, temp = 0.136095003370541,
month_11 = 0.104629510112073, month_12 = 0.10377588975137, weekday = 0.10162171488075,
month_8 = 0.0872754275444851, month_1 = 0.0742447916325022, humidity = 0.0667930411502195,
month_4 = 0.0641386250875992, text_scattered_clouds = 0.058944967751334,
month_5 = 0.0410161574298865, month_3 = 0.0388656146056763, barometer = 0.0385532707949005,
month_9 = 0.0370659909291367, month_7 = 0.0351931395507779, month_6 = 0.027635447313099,
text_mostly_cloudy = 0.0202467735960961, month_2 = 0.0152577431908634,
text_light_rain = 0.00846413168710652, text_sunny = 0.00513080847316623,
text_fog = 0.00319036182896425, workday_on_holiday = 0.00303045921527343,
text_passing_clouds = 0.00235587942164676, text_rain = 0.000150063164697571,
weekend = 0, weekend_on_holiday = 0)), list(c(wind = 0.3471960493154,
temp = 0.204772614566322, month_8 = 0.119633369487987, humidity = 0.114447660606209,
holiday = 0.112215067123671, month_10 = 0.109680992791846, month_11 = 0.0949710751650855,
month_1 = 0.0678540389508553, month_4 = 0.0676970303790074, barometer = 0.0638877490405209,
weekday = 0.0603264305881994, text_mostly_cloudy = 0.059886928575409,
month_7 = 0.0523244261699112, month_3 = 0.0464621031121763, text_scattered_clouds = 0.0426460498828706,
month_5 = 0.0393232886119189, month_9 = 0.0329339301863209, workday_on_holiday = 0.026400691935472,
month_12 = 0.0239766088909189, month_6 = 0.0209643615779743,
text_rain = 0.00470063751244484, month_2 = 0.00435824692036667,
text_fog = 0.00358736017917106, text_passing_clouds = 0.00254604459529451,
text_light_rain = 0.00246286783930867, text_sunny = 0.000557708446459696,
weekend = 0, weekend_on_holiday = 0, protocol_active = 0), c(protocol_active = 0.546549613644543,
wind = 0.443618430590955, holiday = 0.2057616408105, temp = 0.143528428632999,
month_10 = 0.139108116096353, weekday = 0.119753870444551, month_11 = 0.105665854854535,
month_4 = 0.0847140095491025, humidity = 0.0702211903523539,
month_5 = 0.067856426839823, month_9 = 0.0585853496855593, barometer = 0.0466051602491349,
month_8 = 0.0407423583947575, month_1 = 0.0370854357117149, month_6 = 0.0345889221737587,
month_12 = 0.0331118828706341, text_mostly_cloudy = 0.0265744483947316,
month_3 = 0.0250310123421796, text_light_rain = 0.0236595287710666,
month_7 = 0.0236081493886604, text_scattered_clouds = 0.0229368038071515,
month_2 = 0.0119531214563892, text_fog = 0.00546791553037501,
workday_on_holiday = 0.00441453391159821, text_rain = 0.00314937465607303,
text_sunny = 0.00282535660389051, text_passing_clouds = 0.00253598129527737,
weekend = 0, weekend_on_holiday = 0), c(protocol_active = 0.518170012744594,
wind = 0.468760529065347, temp = 0.198249993483989, month_8 = 0.127854839789779,
holiday = 0.115651709099816, humidity = 0.10895871515734, month_1 = 0.104507054764879,
weekday = 0.0970008689541525, barometer = 0.0558000887901608,
month_12 = 0.0520648544022737, month_11 = 0.0498573669270702,
month_3 = 0.0475327540435148, text_mostly_cloudy = 0.0420257895091999,
month_10 = 0.0392210214613824, month_7 = 0.0346112258522878,
month_4 = 0.030376681720957, month_6 = 0.0274944621384594, month_9 = 0.0250618364774626,
workday_on_holiday = 0.0238621021362317, month_5 = 0.0199367708332576,
text_scattered_clouds = 0.0123115063994457, month_2 = 0.00480323263037882,
text_sunny = 0.00464160762224322, text_fog = 0.00246012251002589,
text_light_rain = 0.00221074363608796, text_rain = 0.00193594425875674,
text_passing_clouds = 0.00193056194592034, weekend = 0, weekend_on_holiday = 0
), c(wind = 0.362992887362438, temp = 0.156517904643566, month_12 = 0.114009635327341,
month_10 = 0.105016643601602, month_7 = 0.101879905068133, barometer = 0.0890323752272844,
weekday = 0.0883166062815719, text_mostly_cloudy = 0.0849764846835166,
humidity = 0.07626973618123, month_3 = 0.0604644771419713, workday_on_holiday = 0.0598483406595745,
month_4 = 0.0540825822794581, month_8 = 0.0479107586305469, month_9 = 0.0455382942339936,
month_1 = 0.036916349709489, holiday = 0.0362250549890437, month_11 = 0.0354289955801871,
text_scattered_clouds = 0.027544355493611, text_fog = 0.018845295941842,
text_light_rain = 0.0174401463508169, month_5 = 0.0135907923844196,
text_rain = 0.0128968099968882, month_6 = 0.012569892360263,
month_2 = 0.00509965945535965, text_passing_clouds = 0.00139377025885244,
text_sunny = 0.000367025698946253, weekend = 0, weekend_on_holiday = 0,
protocol_active = 0), c(protocol_active = 0.619563503393299,
wind = 0.457064448140408, holiday = 0.181107866730898, temp = 0.140728671764677,
month_11 = 0.129063893852067, weekday = 0.11427594683384, month_10 = 0.0885211368669627,
month_9 = 0.0783348566882278, month_4 = 0.075404001857456, month_1 = 0.0732684205679306,
month_3 = 0.0566192154215487, humidity = 0.0469606031303847,
month_12 = 0.0465199248622981, month_5 = 0.0434354892472862,
month_8 = 0.0341517087922657, barometer = 0.0340740037986594,
workday_on_holiday = 0.0271233329090149, text_scattered_clouds = 0.0252819455135321,
text_mostly_cloudy = 0.0209707050348469, month_7 = 0.020118997730825,
text_fog = 0.0177517202234142, text_light_rain = 0.0141883356057609,
month_6 = 0.012501962568832, month_2 = 0.00782442912383458, text_rain = 0.00240311886770778,
text_sunny = 0.00235140240465584, text_passing_clouds = 0.001641017195825,
weekend = 0, weekend_on_holiday = 0), c(protocol_active = 0.609327859788725,
wind = 0.456351663566834, holiday = 0.148564431615616, temp = 0.140337292819591,
month_10 = 0.132416416010628, month_11 = 0.117216315071979, weekday = 0.102646726133412,
month_9 = 0.0818879473805598, month_1 = 0.0711949855201882, month_4 = 0.0700700130827537,
humidity = 0.0678324389551247, month_5 = 0.049777553432098, barometer = 0.0466848493424757,
month_12 = 0.0408083424048677, text_mostly_cloudy = 0.0374117362364004,
month_3 = 0.0289161419390688, month_7 = 0.0254772765149833, text_scattered_clouds = 0.0248008842188115,
month_8 = 0.0228434387129598, text_rain = 0.0152162249995285,
text_light_rain = 0.0144390966240625, workday_on_holiday = 0.0139014270811525,
text_fog = 0.0111675927635563, month_6 = 0.00771660135004278,
text_passing_clouds = 0.00333411018372105, month_2 = 0.00315501674433698,
text_sunny = 0.00271693577132569, weekend = 0, weekend_on_holiday = 0
), c(wind = 0.341318757984593, temp = 0.181543743016176, month_10 = 0.13695143016574,
month_1 = 0.11867567475664, text_mostly_cloudy = 0.100970260189399,
holiday = 0.0980616427161045, barometer = 0.0793575984151815,
month_7 = 0.0790023186407231, month_11 = 0.0703358960510832,
weekday = 0.0660567048872761, month_8 = 0.0646335429141987, humidity = 0.0584869976667937,
month_9 = 0.0550697732815506, month_4 = 0.0549736535127431, text_rain = 0.0324340487643226,
text_scattered_clouds = 0.029467215459551, month_5 = 0.026095418599204,
month_12 = 0.0228145297956929, workday_on_holiday = 0.02231496147956,
month_3 = 0.0172067242969555, month_6 = 0.0151089321051142, text_fog = 0.0119331553129859,
month_2 = 0.004686956213666, text_light_rain = 0.00222796628025926,
text_passing_clouds = 0.00213700559004825, text_sunny = 0.00117576091734465,
weekend = 0, weekend_on_holiday = 0, protocol_active = 0), c(wind = 0.317176884816342,
temp = 0.186585429980718, month_10 = 0.114666912663031, month_11 = 0.104605599640779,
barometer = 0.09860398214251, text_mostly_cloudy = 0.0981445614080669,
month_7 = 0.086645777661902, weekday = 0.0827571745079603, month_3 = 0.0822469143395219,
holiday = 0.0741225284600942, humidity = 0.0680909881825519,
month_8 = 0.0676141235433077, month_1 = 0.0666523905343389, month_4 = 0.057138819125979,
month_9 = 0.0566241708282194, workday_on_holiday = 0.0514050400134423,
text_scattered_clouds = 0.0386366823825728, month_2 = 0.0275814191334069,
month_6 = 0.0180563169006692, month_5 = 0.0171425190230017, text_fog = 0.0147302871581154,
text_rain = 0.0113228506870373, month_12 = 0.00608702311249765,
text_light_rain = 0.00384076425344412, text_passing_clouds = 0.00162419812395092,
text_sunny = 0.00161398823166901, weekend = 0, weekend_on_holiday = 0,
protocol_active = 0), c(wind = 0.375885075304381, temp = 0.196911627075252,
month_1 = 0.138145776167852, month_10 = 0.1084922540901, month_7 = 0.102679471840915,
text_mostly_cloudy = 0.101000594539934, humidity = 0.0873952553634127,
holiday = 0.0831717698088636, weekday = 0.0709255464503129, month_11 = 0.0684159875069171,
month_4 = 0.0625302634603284, month_8 = 0.0597528607537757, month_9 = 0.0577152460643418,
barometer = 0.0573343434453839, workday_on_holiday = 0.0532975932012499,
month_3 = 0.0431124968933724, month_12 = 0.0300806329768474,
text_scattered_clouds = 0.0287391537020907, month_2 = 0.0263872490630998,
text_rain = 0.023765753120286, month_5 = 0.0137840943180421,
text_fog = 0.00944782494843987, month_6 = 0.00926343392612626,
text_light_rain = 0.00513122997652807, text_passing_clouds = 0.00192773997607476,
text_sunny = 0.000749526165263181, weekend = 0, weekend_on_holiday = 0,
protocol_active = 0), c(wind = 0.380077804633114, temp = 0.193910785717298,
month_8 = 0.134010390554593, month_11 = 0.13263544712777, month_1 = 0.108483703190367,
humidity = 0.0857712876190871, holiday = 0.0789236757853526,
barometer = 0.0758084804113203, month_10 = 0.0755415201722963,
text_mostly_cloudy = 0.0680279704685786, workday_on_holiday = 0.0658503648376073,
weekday = 0.0563462752284063, month_4 = 0.054099467118469, month_7 = 0.0467023095318018,
month_3 = 0.0433152559594331, month_6 = 0.0356285987785469, text_scattered_clouds = 0.0320350306800973,
month_9 = 0.0316930312848571, protocol_active = 0.0258647354336702,
month_12 = 0.0173648500177142, month_5 = 0.013542126122798, text_fog = 0.0127799333001967,
month_2 = 0.0054027507247214, text_light_rain = 0.00488149158866038,
text_passing_clouds = 0.00411573011748326, text_rain = 0.0039578812850956,
text_sunny = 0.00152551980949809, weekend = 0, weekend_on_holiday = 0
)))
答案 0 :(得分:3)
.id
字段应包含用于存储名称的列名称,因此应为字符串。
这给出了预期的结果:
NamedList %>%
map_dfr(., ~map_dfr(.x, as.list, .id = "NAME2"), .id = "NAME")
答案 1 :(得分:1)
或者const installations = [
{
id: "group1",
Name: "Some name"
},
{id:..., Name:...}
...
]
class App extends React.Component {
state = {
IdInstallGroup: ["group1", "group2", "group3", "group4"],
installations: installations
};
render() {
return <div className="App">
{
this.state.IdInstallGroup.map(group =>
this.state.installations.map(installation =>
<MyComponent id={installation.id} name={installation.Name} isChecked={group === installation.id} />
)
)
}
</div>;
}
}
bind_rows