Reputation: 7107
I cannot seem to bind my lists together correctly.
I have tried:
purrr::map(myList, ~dplyr::bind_rows(.))
Error: Argument 1 must have names
Which does not work.
purrr::map(myList, ~plyr::ldply(.))
Which "appears" to work but does not give me the correct values. When I run:
library(dplyr)
purrr::map(myList, ~plyr::ldply(.) %>%
distinct(protocol_active))
I get the following output:
[[1]]
protocol_active
1 0.4766905
2 0.4277574
3 0.3365723
4 0.4572180
5 0.2857566
6 0.3282195
7 0.3178228
8 0.5150016
9 0.5812856
10 0.4742427
[[2]]
protocol_active
1 0
However in list [[2]][[6]]
I get the following:
myList[[2]][[6]]
protocol_active wind holiday temp
0.609327860 0.456351664 0.148564432 0.14033729
Where protocol_active
has a value > 0, but when I run distinct()
it tells me that list [[2]]
only hae 0
as its unique value.
What am I doing wrong here?
Data:
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
)))
Upvotes: 2
Views: 119
Reputation: 42564
If I understand correctly, the OP wants to create a data frame from a double nested list of named numeric vectors.
Here is an alternative way which flattens the first list level, turns the named vectors into lists which then are combined into a data frame (actually a data.table) by matching column names:
library(magrittr) # piping used here to improve readability
myList %>%
unlist(recursive = FALSE) %>%
lapply(as.list) %>%
data.table::rbindlist(use.names = TRUE)
As a proof, here is the output of str()
Classes ‘data.table’ and 'data.frame': 20 obs. of 29 variables: $ protocol_active : num 0.47669 0.42776 0.00647 0.45722 0.0535 ... $ wind : num 0.422 0.409 0.337 0.387 0.286 ... $ holiday : num 0.2379 0.0866 0.1988 0.1661 0.1545 ... $ month_10 : num 0.1741 0.0551 0.1444 0.0699 0.1501 ... $ month_8 : num 0.1462 0.143 0.0588 0.083 0.0472 ... $ temp : num 0.136 0.138 0.144 0.149 0.135 ... $ month_11 : num 0.117 0.275 0.137 0.272 0.164 ... $ humidity : num 0.0981 0.0898 0.0828 0.093 0.0645 ... $ weekday : num 0.0936 0.1311 0.0824 0.106 0.099 ... $ month_1 : num 0.0758 0.0596 0.1924 0.0928 0.1798 ... $ text_scattered_clouds: num 0.0714 0.049 0.1012 0.0523 0.0775 ... $ month_4 : num 0.0459 0.042 0.0573 0.0415 0.0542 ... $ month_3 : num 0.0446 0.0405 0.0265 0.0187 0.0207 ... $ month_12 : num 0.0401 0.0451 0.0738 0.0184 0.0892 ... $ month_7 : num 0.0397 0.0327 0.0263 0.042 0.0337 ... $ month_9 : num 0.0314 0.0293 0.0259 0.0375 0.0313 ... $ month_6 : num 0.0307 0.0338 0.0403 0.0217 0.0473 ... $ barometer : num 0.0298 0.0356 0.0396 0.0431 0.0359 ... $ month_5 : num 0.0276 0.0359 0.0595 0.0355 0.0524 ... $ text_light_rain : num 0.01658 0.00943 0.00632 0.0201 0.00611 ... $ month_2 : num 0.0166 0.018 0.013 0.0272 0.0163 ... $ text_mostly_cloudy : num 0.0121 0.0271 0.048 0.0298 0.0475 ... $ text_sunny : num 0.00941 0.0103 0.01311 0.00998 0.01055 ... $ text_fog : num 0.00925 0.00807 0.00586 0.05253 0.00589 ... $ workday_on_holiday : num 0.00284 0.00241 0.00982 0.01957 0.02553 ... $ text_passing_clouds : num 0.0015 0.01187 0.00684 0.02744 0.00752 ... $ text_rain : num 0.001312 0.000057 0.000405 0.003292 0.001999 ... $ weekend : num 0 0 0 0 0 0 0 0 0 0 ... $ weekend_on_holiday : num 0 0 0 0 0 0 0 0 0 0 ... - attr(*, ".internal.selfref")=<externalptr>
Upvotes: 2
Reputation: 389055
In base R, one option could be :
do.call(rbind, lapply(myList,function(x)
do.call(rbind, lapply(x, function(y) data.frame(t(y))))))
# protocol_active wind holiday month_10 month_8 temp month_11 humidity ...
#1 0.47669 0.422 0.2379 0.1741 0.1462 0.136 0.1171 0.0981 ...
#2 0.42776 0.409 0.0866 0.0551 0.1430 0.138 0.2751 0.0898 ...
#3 0.00647 0.337 0.1988 0.1444 0.0588 0.144 0.1373 0.0828 ...
#4 0.45722 0.387 0.1661 0.0699 0.0830 0.149 0.2715 0.0930 ...
#5 0.05350 0.286 0.1545 0.1501 0.0472 0.135 0.1643 0.0645 ...
#6 0.04196 0.328 0.1608 0.1137 0.0438 0.122 0.1295 0.0605 ...
#7 0.00000 0.318 0.1854 0.1328 0.0488 0.136 0.1919 0.0683 ...
#8 0.51500 0.369 0.1846 0.0513 0.1115 0.149 0.2346 0.0832 ...
#9 0.58129 0.389 0.1580 0.0610 0.0770 0.120 0.2446 0.0738 ...
#10 0.47424 0.422 0.1826 0.1878 0.0873 0.136 0.1046 0.0668 ...
#11 0.00000 0.347 0.1122 0.1097 0.1196 0.205 0.0950 0.1144 ...
#12 0.54655 0.444 0.2058 0.1391 0.0407 0.144 0.1057 0.0702 ...
#13 0.51817 0.469 0.1157 0.0392 0.1279 0.198 0.0499 0.1090 ...
#14 0.00000 0.363 0.0362 0.1050 0.0479 0.157 0.0354 0.0763 ...
#15 0.61956 0.457 0.1811 0.0885 0.0342 0.141 0.1291 0.0470 ...
#16 0.60933 0.456 0.1486 0.1324 0.0228 0.140 0.1172 0.0678 ...
#17 0.00000 0.341 0.0981 0.1370 0.0646 0.182 0.0703 0.0585 ...
#18 0.00000 0.317 0.0741 0.1147 0.0676 0.187 0.1046 0.0681 ...
#19 0.00000 0.376 0.0832 0.1085 0.0598 0.197 0.0684 0.0874 ...
#20 0.02586 0.380 0.0789 0.0755 0.1340 0.194 0.1326 0.0858 ...
Upvotes: 1
Reputation: 34556
Your list contains lists of named vectors. You can use bind_rows()
if you splice the nested lists.
library(dplyr)
library(purrr)
map_df(myList, ~bind_rows(!!!.x))
# A tibble: 20 x 29
protocol_active wind holiday month_10 month_8 temp month_11 humidity weekday month_1
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0.477 0.422 0.238 0.174 0.146 0.136 0.117 0.0981 0.0936 0.0758
2 0.428 0.409 0.0866 0.0551 0.143 0.138 0.275 0.0898 0.131 0.0596
3 0.00647 0.337 0.199 0.144 0.0588 0.144 0.137 0.0828 0.0824 0.192
4 0.457 0.387 0.166 0.0699 0.0830 0.149 0.272 0.0930 0.106 0.0928
5 0.0535 0.286 0.155 0.150 0.0472 0.135 0.164 0.0645 0.0990 0.180
6 0.0420 0.328 0.161 0.114 0.0438 0.122 0.130 0.0605 0.0832 0.175
7 0 0.318 0.185 0.133 0.0488 0.136 0.192 0.0683 0.0752 0.0980
8 0.515 0.369 0.185 0.0513 0.112 0.149 0.235 0.0832 0.136 0.0524
9 0.581 0.389 0.158 0.0610 0.0770 0.120 0.245 0.0738 0.123 0.0838
10 0.474 0.422 0.183 0.188 0.0873 0.136 0.105 0.0668 0.102 0.0742
11 0 0.347 0.112 0.110 0.120 0.205 0.0950 0.114 0.0603 0.0679
12 0.547 0.444 0.206 0.139 0.0407 0.144 0.106 0.0702 0.120 0.0371
13 0.518 0.469 0.116 0.0392 0.128 0.198 0.0499 0.109 0.0970 0.105
14 0 0.363 0.0362 0.105 0.0479 0.157 0.0354 0.0763 0.0883 0.0369
15 0.620 0.457 0.181 0.0885 0.0342 0.141 0.129 0.0470 0.114 0.0733
16 0.609 0.456 0.149 0.132 0.0228 0.140 0.117 0.0678 0.103 0.0712
17 0 0.341 0.0981 0.137 0.0646 0.182 0.0703 0.0585 0.0661 0.119
18 0 0.317 0.0741 0.115 0.0676 0.187 0.105 0.0681 0.0828 0.0667
19 0 0.376 0.0832 0.108 0.0598 0.197 0.0684 0.0874 0.0709 0.138
20 0.0259 0.380 0.0789 0.0755 0.134 0.194 0.133 0.0858 0.0563 0.108
# ... with 19 more variables: text_scattered_clouds <dbl>, month_4 <dbl>, month_3 <dbl>,
# month_12 <dbl>, month_7 <dbl>, month_9 <dbl>, month_6 <dbl>, barometer <dbl>, month_5 <dbl>,
# text_light_rain <dbl>, month_2 <dbl>, text_mostly_cloudy <dbl>, text_sunny <dbl>,
# text_fog <dbl>, workday_on_holiday <dbl>, text_passing_clouds <dbl>, text_rain <dbl>,
# weekend <dbl>, weekend_on_holiday <dbl>
Upvotes: 3
Reputation: 887291
Here, we can do a double map
and avoid loading multiple packages
library(purrr)
map_dfr(myList, ~ map_dfr(.x, as.list) )
# A tibble: 20 x 29
# protocol_active wind holiday month_10 month_8 temp month_11 humidity weekday month_1 text_scattered_… month_4 month_3 month_12 month_7
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 0.477 0.422 0.238 0.174 0.146 0.136 0.117 0.0981 0.0936 0.0758 0.0714 0.0459 0.0446 0.0401 0.0397
# 2 0.428 0.409 0.0866 0.0551 0.143 0.138 0.275 0.0898 0.131 0.0596 0.0490 0.0420 0.0405 0.0451 0.0327
# 3 0.00647 0.337 0.199 0.144 0.0588 0.144 0.137 0.0828 0.0824 0.192 0.101 0.0573 0.0265 0.0738 0.0263
# 4 0.457 0.387 0.166 0.0699 0.0830 0.149 0.272 0.0930 0.106 0.0928 0.0523 0.0415 0.0187 0.0184 0.0420
# 5 0.0535 0.286 0.155 0.150 0.0472 0.135 0.164 0.0645 0.0990 0.180 0.0775 0.0542 0.0207 0.0892 0.0337
# 6 0.0420 0.328 0.161 0.114 0.0438 0.122 0.130 0.0605 0.0832 0.175 0.123 0.0584 0.0339 0.0997 0.0318
# 7 0 0.318 0.185 0.133 0.0488 0.136 0.192 0.0683 0.0752 0.0980 0.0996 0.0230 0.0190 0.0411 0.0589
# 8 0.515 0.369 0.185 0.0513 0.112 0.149 0.235 0.0832 0.136 0.0524 0.0450 0.0623 0.0141 0.00527 0.0346
# 9 0.581 0.389 0.158 0.0610 0.0770 0.120 0.245 0.0738 0.123 0.0838 0.0591 0.0288 0.0259 0.00949 0.0255
#10 0.474 0.422 0.183 0.188 0.0873 0.136 0.105 0.0668 0.102 0.0742 0.0589 0.0641 0.0389 0.104 0.0352
#11 0 0.347 0.112 0.110 0.120 0.205 0.0950 0.114 0.0603 0.0679 0.0426 0.0677 0.0465 0.0240 0.0523
#12 0.547 0.444 0.206 0.139 0.0407 0.144 0.106 0.0702 0.120 0.0371 0.0229 0.0847 0.0250 0.0331 0.0236
#13 0.518 0.469 0.116 0.0392 0.128 0.198 0.0499 0.109 0.0970 0.105 0.0123 0.0304 0.0475 0.0521 0.0346
#14 0 0.363 0.0362 0.105 0.0479 0.157 0.0354 0.0763 0.0883 0.0369 0.0275 0.0541 0.0605 0.114 0.102
#15 0.620 0.457 0.181 0.0885 0.0342 0.141 0.129 0.0470 0.114 0.0733 0.0253 0.0754 0.0566 0.0465 0.0201
#16 0.609 0.456 0.149 0.132 0.0228 0.140 0.117 0.0678 0.103 0.0712 0.0248 0.0701 0.0289 0.0408 0.0255
#17 0 0.341 0.0981 0.137 0.0646 0.182 0.0703 0.0585 0.0661 0.119 0.0295 0.0550 0.0172 0.0228 0.0790
#18 0 0.317 0.0741 0.115 0.0676 0.187 0.105 0.0681 0.0828 0.0667 0.0386 0.0571 0.0822 0.00609 0.0866
#19 0 0.376 0.0832 0.108 0.0598 0.197 0.0684 0.0874 0.0709 0.138 0.0287 0.0625 0.0431 0.0301 0.103
#20 0.0259 0.380 0.0789 0.0755 0.134 0.194 0.133 0.0858 0.0563 0.108 0.0320 0.0541 0.0433 0.0174 0.0467
# … with 14 more variables: month_9 <dbl>, month_6 <dbl>, barometer <dbl>, month_5 <dbl>, text_light_rain <dbl>, month_2 <dbl>,
# text_mostly_cloudy <dbl>, text_sunny <dbl>, text_fog <dbl>, workday_on_holiday <dbl>, text_passing_clouds <dbl>, text_rain <dbl>,
# weekend <dbl>, weekend_on_holiday <dbl>
Or another option is unnest_wider
library(tidyr)
map_dfr(myList, ~ tibble(col = .x) %>%
unnest_wider(col))
# A tibble: 20 x 29
# protocol_active wind holiday month_10 month_8 temp month_11 humidity weekday month_1 text_scattered_… month_4 month_3 month_12 month_7
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 0.477 0.422 0.238 0.174 0.146 0.136 0.117 0.0981 0.0936 0.0758 0.0714 0.0459 0.0446 0.0401 0.0397
# 2 0.428 0.409 0.0866 0.0551 0.143 0.138 0.275 0.0898 0.131 0.0596 0.0490 0.0420 0.0405 0.0451 0.0327
# 3 0.00647 0.337 0.199 0.144 0.0588 0.144 0.137 0.0828 0.0824 0.192 0.101 0.0573 0.0265 0.0738 0.0263
# 4 0.457 0.387 0.166 0.0699 0.0830 0.149 0.272 0.0930 0.106 0.0928 0.0523 0.0415 0.0187 0.0184 0.0420
# 5 0.0535 0.286 0.155 0.150 0.0472 0.135 0.164 0.0645 0.0990 0.180 0.0775 0.0542 0.0207 0.0892 0.0337
# 6 0.0420 0.328 0.161 0.114 0.0438 0.122 0.130 0.0605 0.0832 0.175 0.123 0.0584 0.0339 0.0997 0.0318
# 7 0 0.318 0.185 0.133 0.0488 0.136 0.192 0.0683 0.0752 0.0980 0.0996 0.0230 0.0190 0.0411 0.0589
# 8 0.515 0.369 0.185 0.0513 0.112 0.149 0.235 0.0832 0.136 0.0524 0.0450 0.0623 0.0141 0.00527 0.0346
# 9 0.581 0.389 0.158 0.0610 0.0770 0.120 0.245 0.0738 0.123 0.0838 0.0591 0.0288 0.0259 0.00949 0.0255
#10 0.474 0.422 0.183 0.188 0.0873 0.136 0.105 0.0668 0.102 0.0742 0.0589 0.0641 0.0389 0.104 0.0352
#11 0 0.347 0.112 0.110 0.120 0.205 0.0950 0.114 0.0603 0.0679 0.0426 0.0677 0.0465 0.0240 0.0523
#12 0.547 0.444 0.206 0.139 0.0407 0.144 0.106 0.0702 0.120 0.0371 0.0229 0.0847 0.0250 0.0331 0.0236
#13 0.518 0.469 0.116 0.0392 0.128 0.198 0.0499 0.109 0.0970 0.105 0.0123 0.0304 0.0475 0.0521 0.0346
#14 0 0.363 0.0362 0.105 0.0479 0.157 0.0354 0.0763 0.0883 0.0369 0.0275 0.0541 0.0605 0.114 0.102
#15 0.620 0.457 0.181 0.0885 0.0342 0.141 0.129 0.0470 0.114 0.0733 0.0253 0.0754 0.0566 0.0465 0.0201
#16 0.609 0.456 0.149 0.132 0.0228 0.140 0.117 0.0678 0.103 0.0712 0.0248 0.0701 0.0289 0.0408 0.0255
#17 0 0.341 0.0981 0.137 0.0646 0.182 0.0703 0.0585 0.0661 0.119 0.0295 0.0550 0.0172 0.0228 0.0790
#18 0 0.317 0.0741 0.115 0.0676 0.187 0.105 0.0681 0.0828 0.0667 0.0386 0.0571 0.0822 0.00609 0.0866
#19 0 0.376 0.0832 0.108 0.0598 0.197 0.0684 0.0874 0.0709 0.138 0.0287 0.0625 0.0431 0.0301 0.103
#20 0.0259 0.380 0.0789 0.0755 0.134 0.194 0.133 0.0858 0.0563 0.108 0.0320 0.0541 0.0433 0.0174 0.0467
# … with 14 more variables: month_9 <dbl>, month_6 <dbl>, barometer <dbl>, month_5 <dbl>, text_light_rain <dbl>, month_2 <dbl>,
# text_mostly_cloudy <dbl>, text_sunny <dbl>, text_fog <dbl>, workday_on_holiday <dbl>, text_passing_clouds <dbl>, text_rain <dbl>,
# weekend <dbl>, weekend_on_holiday <dbl>
Or another option is reduce/bind_rows
library(dplyr)
map_dfr(myList, reduce, bind_rows)
# A tibble: 20 x 29
# protocol_active wind holiday month_10 month_8 temp month_11 humidity weekday month_1 text_scattered_… month_4 month_3 month_12 month_7
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 0.477 0.422 0.238 0.174 0.146 0.136 0.117 0.0981 0.0936 0.0758 0.0714 0.0459 0.0446 0.0401 0.0397
# 2 0.428 0.409 0.0866 0.0551 0.143 0.138 0.275 0.0898 0.131 0.0596 0.0490 0.0420 0.0405 0.0451 0.0327
# 3 0.00647 0.337 0.199 0.144 0.0588 0.144 0.137 0.0828 0.0824 0.192 0.101 0.0573 0.0265 0.0738 0.0263
# 4 0.457 0.387 0.166 0.0699 0.0830 0.149 0.272 0.0930 0.106 0.0928 0.0523 0.0415 0.0187 0.0184 0.0420
# 5 0.0535 0.286 0.155 0.150 0.0472 0.135 0.164 0.0645 0.0990 0.180 0.0775 0.0542 0.0207 0.0892 0.0337
# 6 0.0420 0.328 0.161 0.114 0.0438 0.122 0.130 0.0605 0.0832 0.175 0.123 0.0584 0.0339 0.0997 0.0318
# 7 0 0.318 0.185 0.133 0.0488 0.136 0.192 0.0683 0.0752 0.0980 0.0996 0.0230 0.0190 0.0411 0.0589
# 8 0.515 0.369 0.185 0.0513 0.112 0.149 0.235 0.0832 0.136 0.0524 0.0450 0.0623 0.0141 0.00527 0.0346
# 9 0.581 0.389 0.158 0.0610 0.0770 0.120 0.245 0.0738 0.123 0.0838 0.0591 0.0288 0.0259 0.00949 0.0255
#10 0.474 0.422 0.183 0.188 0.0873 0.136 0.105 0.0668 0.102 0.0742 0.0589 0.0641 0.0389 0.104 0.0352
#11 0 0.347 0.112 0.110 0.120 0.205 0.0950 0.114 0.0603 0.0679 0.0426 0.0677 0.0465 0.0240 0.0523
#12 0.547 0.444 0.206 0.139 0.0407 0.144 0.106 0.0702 0.120 0.0371 0.0229 0.0847 0.0250 0.0331 0.0236
#13 0.518 0.469 0.116 0.0392 0.128 0.198 0.0499 0.109 0.0970 0.105 0.0123 0.0304 0.0475 0.0521 0.0346
#14 0 0.363 0.0362 0.105 0.0479 0.157 0.0354 0.0763 0.0883 0.0369 0.0275 0.0541 0.0605 0.114 0.102
#15 0.620 0.457 0.181 0.0885 0.0342 0.141 0.129 0.0470 0.114 0.0733 0.0253 0.0754 0.0566 0.0465 0.0201
#16 0.609 0.456 0.149 0.132 0.0228 0.140 0.117 0.0678 0.103 0.0712 0.0248 0.0701 0.0289 0.0408 0.0255
#17 0 0.341 0.0981 0.137 0.0646 0.182 0.0703 0.0585 0.0661 0.119 0.0295 0.0550 0.0172 0.0228 0.0790
#18 0 0.317 0.0741 0.115 0.0676 0.187 0.105 0.0681 0.0828 0.0667 0.0386 0.0571 0.0822 0.00609 0.0866
#19 0 0.376 0.0832 0.108 0.0598 0.197 0.0684 0.0874 0.0709 0.138 0.0287 0.0625 0.0431 0.0301 0.103
#20 0.0259 0.380 0.0789 0.0755 0.134 0.194 0.133 0.0858 0.0563 0.108 0.0320 0.0541 0.0433 0.0174 0.0467
# … with 14 more variables: month_9 <dbl>, month_6 <dbl>, barometer <dbl>, month_5 <dbl>, text_light_rain <dbl>, month_2 <dbl>,
# text_mostly_cloudy <dbl>, text_sunny <dbl>, text_fog <dbl>, workday_on_holiday <dbl>, text_passing_clouds <dbl>, text_rain <dbl>,
# weekend <dbl>, weekend_on_holiday <dbl>
>
Upvotes: 3