Распечатывать элементы из списка в R с различными вложенными уровнями - PullRequest
1 голос
/ 20 октября 2019

У меня есть список в R со структурой, как в выводе dput.

Обновление:

structure(list(name = c("\\text{Students are able to identify relationship between l (or ml) and cm³\n}", 
"\\text{Students are able to write down the notation and representations of fractions \n}", 
"\\text{Scientific enquiry}", "\\text{Polska w okresie rozbicia dzielnicowego.}"
), index = c(26L, 39L, 0L, 5L), learningFactorType = c("LEARNING_OBJECTIVE", 
"LEARNING_OBJECTIVE", "LEARNING_OBJECTIVE", "LEARNING_OBJECTIVE"
), childFactors = list(structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(`_id` = list(structure(as.raw(c(0xee, 0x41, 
    0x32, 0x09, 0x81, 0x82, 0xf4, 0xac, 0x27, 0x49, 0xc2, 0x0b, 
    0x70, 0x65, 0x05, 0x89)), type = as.raw(0x03)), structure(as.raw(c(0xdc, 
    0x46, 0xaf, 0x85, 0x60, 0x2b, 0x6a, 0x04, 0x15, 0x48, 0x7c, 
    0xa5, 0xd0, 0xbc, 0x27, 0x8b)), type = as.raw(0x03)), structure(as.raw(c(0x76, 
    0x4a, 0x90, 0xc0, 0x90, 0xc6, 0xf1, 0x76, 0x18, 0x51, 0x13, 
    0xc1, 0xae, 0xa1, 0x03, 0x84)), type = as.raw(0x03)), structure(as.raw(c(0xec, 
    0x42, 0x98, 0x7a, 0xd4, 0x16, 0x23, 0x3f, 0x43, 0xfd, 0x36, 
    0x5d, 0xa1, 0x4a, 0xcd, 0xa8)), type = as.raw(0x03))), name = c("\\text{ Ideas and evidence}", 
    "\\text{Plan investigative work}", "\\text{Obtain and present evidence}", 
    "\\text{ Consider evidence and approach}"), index = 0:3, 
        childFactors = list(structure(list(`_id` = list(structure(as.raw(c(0xee, 
        0x49, 0x92, 0x4f, 0xe2, 0x10, 0xb8, 0x33, 0x6f, 0xbe, 
        0xd2, 0x9f, 0x46, 0x82, 0x36, 0x9d)), type = as.raw(0x03)), 
            structure(as.raw(c(0xa2, 0x4e, 0x9c, 0x07, 0x44, 
            0x1b, 0x7b, 0x44, 0xa3, 0x03, 0xe9, 0x22, 0x69, 0xaf, 
            0x5b, 0x85)), type = as.raw(0x03))), name = c("\\text{Collect evidence in a variety of contexts (4Ep1)}", 
        "\\text{Test an idea or prediction based on scientific knowledge and understanding (4Ep2)}"
        ), index = 0:1, childFactors = list(list(), list()), 
            exerciseIdList = list(list(), list()), knowledgeBaseEntryIdList = list(
                list(), list()), linkedSourceList = list(structure(list(
                publisherId = c(193, 193, 193, 193, 193, 193), 
                categoryId = c(22610, 22610, 22610, 22612, 22614, 
                22614), levelId = c(1001, 1001, 1001, 1001, 1001, 
                1001), subcategoryIdList = list(22618, 22619, 
                  22620, 22628, 22631, 22634), exerciseIdList = list(
                  c(281313, 281322, 281439, 281442), c(281310, 
                  281312, 281437), c(281307, 281324), c(325294, 
                  325296, 325380, 325394, 325448, 325473, 325516
                  ), c(328850, 328851, 328853, 328856, 328861, 
                  328869, 328870, 328871), c(328854, 335329)), 
                knowledgeBaseEntryIdList = list(list(), list(), 
                  list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
            6L)), structure(list(publisherId = c(193, 193), categoryId = c(22614, 
            22614), levelId = c(1001, 1001), subcategoryIdList = list(
                22632, 22633), exerciseIdList = list(c(328852, 
            335327), c(328865, 335324)), knowledgeBaseEntryIdList = list(
                list(), list())), class = "data.frame", row.names = 1:2))), class = "data.frame", row.names = 1:2), 
            structure(list(`_id` = list(structure(as.raw(c(0x43, 
            0x46, 0xbd, 0xa0, 0x8f, 0xf6, 0x37, 0xad, 0x48, 0x37, 
            0xeb, 0x2f, 0x6f, 0xfe, 0x34, 0xb4)), type = as.raw(0x03)), 
                structure(as.raw(c(0xca, 0x4b, 0x33, 0x04, 0x0b, 
                0x2f, 0x1d, 0x75, 0xc6, 0x84, 0xaa, 0xff, 0xfb, 
                0x4c, 0x95, 0xa8)), type = as.raw(0x03)), structure(as.raw(c(0xcc, 
                0x45, 0xa4, 0xec, 0x0a, 0xb1, 0x5a, 0x02, 0x29, 
                0xf2, 0x58, 0x21, 0x58, 0x29, 0xab, 0x8a)), type = as.raw(0x03))), 
                name = c("\\text{Suggest questions that can be tested and make predictions; \ncommunicate these (4Ep3)}", 
                "\\text{Design a fair test and plan how to collect sufficient evidence (4Ep4)}", 
                "\\text{Choose apparatus and decide what to measure (4Ep5)}"
                ), index = 0:2, childFactors = list(list(), list(), 
                  list()), exerciseIdList = list(list(), list(), 
                  list()), knowledgeBaseEntryIdList = list(list(), 
                  list(), list()), linkedSourceList = list(structure(list(
                  publisherId = c(193, 193, 193, 193), categoryId = c(22611, 
                  22611, 22615, 22615), levelId = c(1001, 1001, 
                  1001, 1001), subcategoryIdList = list(22624, 
                    22625, 22635, 22637), exerciseIdList = list(
                    c(325414, 325415, 325420, 325433), c(325416, 
                    325417, 325418, 325419, 325423, 325427, 325430, 
                    325434, 334617, 334647, 334658), c(328887, 
                    328891), c(328895, 328898, 328904)), knowledgeBaseEntryIdList = list(
                    list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
                4L)), structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
                  structure(list(publisherId = 193, categoryId = 22611, 
                    levelId = 1001, subcategoryIdList = list(
                      22625), exerciseIdList = list(c(325416, 
                    325417, 325418, 325419, 325423, 325427, 325430, 
                    325434, 334617, 334647, 334658)), knowledgeBaseEntryIdList = list(
                      list())), class = "data.frame", row.names = 1L))), class = "data.frame", row.names = c(NA, 
            3L)), structure(list(`_id` = list(structure(as.raw(c(0xf1, 
            0x41, 0xd0, 0xff, 0x4c, 0xaf, 0x1a, 0x7c, 0x8f, 0x4e, 
            0x8a, 0xdb, 0xdb, 0xd2, 0x87, 0xa7)), type = as.raw(0x03)), 
                structure(as.raw(c(0x7f, 0x42, 0xce, 0xf2, 0x3f, 
                0xe4, 0xc3, 0x9f, 0xb7, 0x17, 0x52, 0xfe, 0xb3, 
                0x8a, 0xc9, 0x89)), type = as.raw(0x03)), structure(as.raw(c(0x77, 
                0x49, 0xcc, 0x51, 0xb0, 0x85, 0x03, 0xf5, 0x72, 
                0xeb, 0x2f, 0xe5, 0x6e, 0x32, 0x53, 0x8b)), type = as.raw(0x03)), 
                structure(as.raw(c(0xe1, 0x40, 0x24, 0xb9, 0x1e, 
                0x32, 0xbe, 0xca, 0x33, 0x5e, 0x9e, 0x3d, 0xd0, 
                0x2f, 0x1a, 0x87)), type = as.raw(0x03))), name = c("\\text{Make relevant observations and comparisons in a variety of \ncontexts (4Eo1)}", 
            "\\text{Measure temperature, time, force and length (4Eo2)}", 
            "\\text{Begin to think about the need for repeated measurements of, \nfor example, length (4Eo3)}", 
            "\\text{Present results in drawings, bar charts and tables (4Eo4)}"
            ), index = 0:3, childFactors = list(list(), list(), 
                list(), list()), exerciseIdList = list(list(), 
                list(), list(), list()), knowledgeBaseEntryIdList = list(
                list(), list(), list(), list()), linkedSourceList = list(
                structure(list(publisherId = c(193, 193, 193, 
                193, 193), categoryId = c(22610, 22610, 22610, 
                22612, 22614), levelId = c(1001, 1001, 1001, 
                1001, 1001), subcategoryIdList = list(22619, 
                  22620, 22621, 22628, 22631), exerciseIdList = list(
                  c(281310, 281312, 281437), c(281307, 281324
                  ), c(281308, 281326), c(325294, 325296, 325380, 
                  325394, 325448, 325473, 325516), c(328850, 
                  328851, 328853, 328856, 328861, 328869, 328870, 
                  328871)), knowledgeBaseEntryIdList = list(list(), 
                  list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
                5L)), structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
                structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
                structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"))), class = "data.frame", row.names = c(NA, 
            4L)), structure(list(`_id` = list(structure(as.raw(c(0xc1, 
            0x41, 0x64, 0x24, 0x4d, 0x96, 0x1d, 0xc5, 0x4b, 0x18, 
            0x9f, 0xc3, 0xe2, 0xfe, 0x82, 0xb9)), type = as.raw(0x03)), 
                structure(as.raw(c(0x8a, 0x44, 0x8a, 0x41, 0xed, 
                0x1d, 0x70, 0xdc, 0x81, 0x96, 0x29, 0x0a, 0x49, 
                0xe8, 0x73, 0xa3)), type = as.raw(0x03)), structure(as.raw(c(0x9d, 
                0x4a, 0x23, 0x7c, 0x2a, 0x57, 0x55, 0x31, 0xca, 
                0xd4, 0x17, 0xff, 0x32, 0x9b, 0xfa, 0x9c)), type = as.raw(0x03))), 
                name = c("\\text{Identify simple trends and patterns in results and suggest \nexplanations for some of these (4Eo5)}", 
                "\\text{Explain what the evidence shows and whether it supports \npredictions.  Communicate this clearly to others (4Eo6)}", 
                "\\text{Link evidence to scientific knowledge and understanding in \nsome contexts (4Eo7)}"
                ), index = 0:2, childFactors = list(list(), list(), 
                  list()), exerciseIdList = list(list(), list(), 
                  list()), knowledgeBaseEntryIdList = list(list(), 
                  list(), list()), linkedSourceList = list(structure(list(
                  publisherId = c(193, 193, 193, 193), categoryId = c(22611, 
                  22614, 22614, 22615), levelId = c(1001, 1001, 
                  1001, 1001), subcategoryIdList = list(22625, 
                    22632, 22633, 22636), exerciseIdList = list(
                    c(325416, 325417, 325418, 325419, 325423, 
                    325427, 325430, 325434, 334617, 334647, 334658
                    ), c(328852, 335327), c(328865, 335324), 
                    c(328886, 328888, 328903)), knowledgeBaseEntryIdList = list(
                    list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
                4L)), structure(list(publisherId = 193, categoryId = 22615, 
                  levelId = 1001, subcategoryIdList = list(22637), 
                  exerciseIdList = list(c(328895, 328898, 328904
                  )), knowledgeBaseEntryIdList = list(list())), class = "data.frame", row.names = 1L), 
                  structure(list(publisherId = c(193, 193, 193
                  ), categoryId = c(22612, 22614, 22614), levelId = c(1001, 
                  1001, 1001), subcategoryIdList = list(22628, 
                    22633, 22634), exerciseIdList = list(c(325294, 
                  325296, 325380, 325394, 325448, 325473, 325516
                  ), c(328865, 335324), c(328854, 335329)), knowledgeBaseEntryIdList = list(
                    list(), list(), list())), class = "data.frame", row.names = c(NA, 
                  3L)))), class = "data.frame", row.names = c(NA, 
            3L))), exerciseIdList = list(list(), list(), list(), 
            list()), knowledgeBaseEntryIdList = list(list(), 
            list(), list(), list()), linkedSourceList = list(
            structure(list(publisherId = c(193, 193, 193, 193, 
            193, 193, 193, 193), categoryId = c(22610, 22610, 
            22610, 22612, 22614, 22614, 22614, 22614), levelId = c(1001, 
            1001, 1001, 1001, 1001, 1001, 1001, 1001), subcategoryIdList = list(
                22618, 22619, 22620, 22628, 22631, 22634, 22632, 
                22633), exerciseIdList = list(c(281313, 281322, 
            281439, 281442), c(281310, 281312, 281437), c(281307, 
            281324), c(325294, 325296, 325380, 325394, 325448, 
            325473, 325516), c(328850, 328851, 328853, 328856, 
            328861, 328869, 328870, 328871), c(328854, 335329
            ), c(328852, 335327), c(328865, 335324)), knowledgeBaseEntryIdList = list(
                list(), list(), list(), list(), list(), list(), 
                list(), list())), class = "data.frame", row.names = c(NA, 
            8L)), structure(list(publisherId = c(193, 193, 193, 
            193, 193), categoryId = c(22611, 22611, 22615, 22615, 
            22611), levelId = c(1001, 1001, 1001, 1001, 1001), 
                subcategoryIdList = list(22624, 22625, 22635, 
                  22637, 22625), exerciseIdList = list(c(325414, 
                325415, 325420, 325433), c(325416, 325417, 325418, 
                325419, 325423, 325427, 325430, 325434, 334617, 
                334647, 334658), c(328887, 328891), c(328895, 
                328898, 328904), c(325416, 325417, 325418, 325419, 
                325423, 325427, 325430, 325434, 334617, 334647, 
                334658)), knowledgeBaseEntryIdList = list(list(), 
                  list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
            5L)), structure(list(publisherId = c(193, 193, 193, 
            193, 193), categoryId = c(22610, 22610, 22610, 22612, 
            22614), levelId = c(1001, 1001, 1001, 1001, 1001), 
                subcategoryIdList = list(22619, 22620, 22621, 
                  22628, 22631), exerciseIdList = list(c(281310, 
                281312, 281437), c(281307, 281324), c(281308, 
                281326), c(325294, 325296, 325380, 325394, 325448, 
                325473, 325516), c(328850, 328851, 328853, 328856, 
                328861, 328869, 328870, 328871)), knowledgeBaseEntryIdList = list(
                  list(), list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
            5L)), structure(list(publisherId = c(193, 193, 193, 
            193, 193, 193, 193, 193), categoryId = c(22611, 22614, 
            22614, 22615, 22615, 22612, 22614, 22614), levelId = c(1001, 
            1001, 1001, 1001, 1001, 1001, 1001, 1001), subcategoryIdList = list(
                22625, 22632, 22633, 22636, 22637, 22628, 22633, 
                22634), exerciseIdList = list(c(325416, 325417, 
            325418, 325419, 325423, 325427, 325430, 325434, 334617, 
            334647, 334658), c(328852, 335327), c(328865, 335324
            ), c(328886, 328888, 328903), c(328895, 328898, 328904
            ), c(325294, 325296, 325380, 325394, 325448, 325473, 
            325516), c(328865, 335324), c(328854, 335329)), knowledgeBaseEntryIdList = list(
                list(), list(), list(), list(), list(), list(), 
                list(), list())), class = "data.frame", row.names = c(NA, 
            8L)))), class = "data.frame", row.names = c(NA, 4L
    )), structure(list(`_id` = list(structure(as.raw(c(0x76, 
    0x4f, 0x14, 0xee, 0xb1, 0x19, 0x89, 0xcd, 0x04, 0xd3, 0x44, 
    0x33, 0xa9, 0x1a, 0x6a, 0xbc)), type = as.raw(0x03)), structure(as.raw(c(0x3d, 
    0x4d, 0x57, 0x27, 0x96, 0x1a, 0x86, 0xc0, 0xf4, 0x27, 0x5b, 
    0x2d, 0x19, 0x32, 0xd2, 0x86)), type = as.raw(0x03)), structure(as.raw(c(0x44, 
    0x47, 0xac, 0x85, 0x90, 0x69, 0x04, 0x27, 0x68, 0x4d, 0x12, 
    0x1a, 0x79, 0xfd, 0x76, 0xa6)), type = as.raw(0x03)), structure(as.raw(c(0x4f, 
    0x49, 0x90, 0xd5, 0x40, 0x9c, 0x66, 0xe5, 0x76, 0x22, 0x05, 
    0x7a, 0xaf, 0xd2, 0x95, 0xac)), type = as.raw(0x03)), structure(as.raw(c(0x8c, 
    0x45, 0xfa, 0x87, 0xc8, 0x74, 0x08, 0xaf, 0xba, 0x3e, 0xb1, 
    0x22, 0xb4, 0x91, 0xa0, 0xa1)), type = as.raw(0x03))), name = c("\\text{Umieszczanie w czasie i przestrzeni Polski okresu rozbicia dzielnicowego.}", 
    "\\text{Opisywanie przyczyn oraz wskazywanie skutków rozbicia dzielnicowego.}", 
    "\\text{Umieszczanie w czasie najważniejszych wydarzeń związanych z relacjami polsko-krzyżackimi oraz zagrożeniem najazdami tatarskimi w okresie rozbicia dzielnicowego.}", 
    "\\text{Opisywanie przemiany społecznej i gospodarczej, z uwzględnieniem ruchu osadniczego.}", 
    "\\text{Charakteryzowanie procesu zjednoczenia państwa polskiego na przełomie XIII i XIV wieku, wskazując na rolę władców piastowskich (ze szczególnym uwzględnieniem roli Władysława Łokietka) oraz Kościoła.}"
    ), index = 0:4, childFactors = list(list(), list(), list(), 
        list(), list()), exerciseIdList = list(list(), list(), 
        list(), list(), list()), knowledgeBaseEntryIdList = list(
        list(), list(), list(), list(), list()), linkedSourceList = list(
        list(), list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
    5L))), exerciseIdList = list(list(), list(), list(), list()), 
    levelIdSet = list(462, 459, 1001, c(34, 857, 877)), knowledgeBaseEntryIdList = list(
        list(), list(), list(), list()), subjectId = c(49, 49, 
    357, 9), linkedSourceList = list(structure(list(publisherId = 111, 
        categoryId = 42281, levelId = 462, subcategoryIdList = list(
            42284), exerciseIdList = list(c(495048, 495047, 495043, 
        495044, 495045, 495046, 495049, 495050)), knowledgeBaseEntryIdList = list(
            list())), class = "data.frame", row.names = 1L), 
        structure(list(publisherId = 111, categoryId = 41394, 
            levelId = 459, subcategoryIdList = list(41395), exerciseIdList = list(
                c(473272, 473270, 473269, 473262, 473261, 465453, 
                465452)), knowledgeBaseEntryIdList = list(list())), class = "data.frame", row.names = 1L), 
        structure(list(publisherId = c(193, 193, 193, 193, 193, 
        193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 
        193, 193, 193, 193, 193, 193, 193, 193, 193, 193), categoryId = c(22610, 
        22610, 22610, 22612, 22614, 22614, 22614, 22614, 22611, 
        22611, 22615, 22615, 22611, 22610, 22610, 22610, 22612, 
        22614, 22611, 22614, 22614, 22615, 22615, 22612, 22614, 
        22614), levelId = c(1001, 1001, 1001, 1001, 1001, 1001, 
        1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 
        1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 
        1001, 1001), subcategoryIdList = list(22618, 22619, 22620, 
            22628, 22631, 22634, 22632, 22633, 22624, 22625, 
            22635, 22637, 22625, 22619, 22620, 22621, 22628, 
            22631, 22625, 22632, 22633, 22636, 22637, 22628, 
            22633, 22634), exerciseIdList = list(c(281313, 281322, 
        281439, 281442), c(281310, 281312, 281437), c(281307, 
        281324), c(325294, 325296, 325380, 325394, 325448, 325473, 
        325516), c(328850, 328851, 328853, 328856, 328861, 328869, 
        328870, 328871), c(328854, 335329), c(328852, 335327), 
            c(328865, 335324), c(325414, 325415, 325420, 325433
            ), c(325416, 325417, 325418, 325419, 325423, 325427, 
            325430, 325434, 334617, 334647, 334658), c(328887, 
            328891), c(328895, 328898, 328904), c(325416, 325417, 
            325418, 325419, 325423, 325427, 325430, 325434, 334617, 
            334647, 334658), c(281310, 281312, 281437), c(281307, 
            281324), c(281308, 281326), c(325294, 325296, 325380, 
            325394, 325448, 325473, 325516), c(328850, 328851, 
            328853, 328856, 328861, 328869, 328870, 328871), 
            c(325416, 325417, 325418, 325419, 325423, 325427, 
            325430, 325434, 334617, 334647, 334658), c(328852, 
            335327), c(328865, 335324), c(328886, 328888, 328903
            ), c(328895, 328898, 328904), c(325294, 325296, 325380, 
            325394, 325448, 325473, 325516), c(328865, 335324
            ), c(328854, 335329)), knowledgeBaseEntryIdList = list(
            list(), list(), list(), list(), list(), list(), list(), 
            list(), list(), list(), list(), list(), list(), list(), 
            list(), list(), list(), list(), list(), list(), list(), 
            list(), list(), list(), list(), list())), class = "data.frame", row.names = c(NA, 
        26L)), structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")), 
    treeId = list(structure(as.raw(c(0xa6, 0x48, 0x30, 0x23, 
    0xe1, 0xce, 0xc1, 0x0e, 0x4d, 0x56, 0xe0, 0xc6, 0x6d, 0x71, 
    0x51, 0x96)), type = as.raw(0x03)), structure(as.raw(c(0x27, 
    0x4d, 0xc2, 0xf7, 0xcc, 0xcb, 0x8b, 0x82, 0x2f, 0x20, 0x25, 
    0x72, 0x33, 0x14, 0xee, 0xb7)), type = as.raw(0x03)), structure(as.raw(c(0x7d, 
    0x49, 0x2a, 0xf1, 0x7f, 0xde, 0xff, 0x2a, 0x37, 0x11, 0x33, 
    0x09, 0xaa, 0xa4, 0xd9, 0x87)), type = as.raw(0x03)), structure(as.raw(c(0xbb, 
    0x46, 0x98, 0x1b, 0xa8, 0x19, 0xeb, 0x30, 0x1b, 0x35, 0xf6, 
    0x22, 0x0f, 0xb2, 0x4c, 0x99)), type = as.raw(0x03))), version = c(111, 
    123, 104, 224), indexAlias = c(NA_character_, NA_character_, 
    NA_character_, NA_character_)), row.names = c(1L, 2L, 3L, 
8L), class = "data.frame")



Я хочу распечатать каждое имя li [[1]] подсписка, а также подсписок пятого элемента li [[9]] [[5]] с exerc_ids.

Пакет purrr позволяет мне просто получить элементы li [[9]], но я не уверен, как отобразить имя li [[1]] в соответствующем списке выше.

ex_id<-li[[9]]
df_ex_id <- as.data.frame(unlist(map(ex.id,5)))

Я пытался использовать функцию for:

name_exid <- for (i in li$name) {
print(li$name) + print(li$exerciseIdList[[1]])  
}

Но я получаю сообщение об ошибке и с треском провалился: (

В результате я хотел бы получить столбец A с именем и столбец B с ex.ids

Ответы [ 2 ]

0 голосов
/ 20 октября 2019

Обновление

Это было довольно сложно, но это работает в вашем новом списке.

library(tidyverse)

li %>% 
  map(enframe) %>% 
  `[`(., c("name", "linkedSourceList")) %>% 
  bind_cols() %>% 
  unnest(value1) %>% 
  select(name = "value", exerciseIdList) %>% 
  unnest(exerciseIdList)

Старый ответ

Вот подход, основанный на конвейере, начиная с вашего исходного списка li:

library(tidyverse)

li %>%
  pluck("linkedSourceList") %>%           # get list element called linkedSourceList
  map("exerciseIdList") %>%               # extract elements called "exerciseIdList
  flatten %>%                             # remove hierarchy level
  set_names(li[["name"]]) %>%             # set_names of sub-list
  enframe(value = "excerciseIdList") %>%  # put list in a tibble with a list-column
  unnest(excerciseIdList)                 # unnest list-column
0 голосов
/ 20 октября 2019

Рассмотрим базовые R Map (обертка для mapply) для поэтапной итерации между необходимыми элементами для привязки к списку или фрейму данныхКроме того, sapply может помочь извлечь необходимый вложенный список по всем фреймам данных в li[[9]].

extract_list <- Map(function(nm, id, ex) list(name=nm, index=id, excerciseIdList=ex),
                    li$name,
                    li$index,
                    sapply(li[[9]], `[[`, "exerciseIdList"), USE.NAMES=FALSE)

extract_list
# [[1]]
# [[1]]$name
# [1] "\\text{Students are able to identify relationship between l (or ml) and cm³\n}"
# 
# [[1]]$index
# [1] 26
# 
# [[1]]$excerciseIdList
# [1] 495048 495047 495043 495044 495045 495046 495049 495050
# 
# 
# [[2]]
# [[2]]$name
# [1] "\\text{Students are able to write down the notation and representations of fractions \n}"
# 
# [[2]]$index
# [1] 39
# 
# [[2]]$excerciseIdList
# [1] 473272 473270 473269 473262 473261 465453 465452

Чтобы построить фрейм данных:

df_list <- Map(function(nm, id, ex) data.frame(name=nm, index=id, excerciseIdList=ex,
                                               stringsAsFactors = FALSE),
               li$name,
               li$index,
               sapply(li[[9]], `[[`, "exerciseIdList"))

final_df <- do.call(rbind, unname(df_list))

final_df    
#                                                                                        name index excerciseIdList
# 1            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495048
# 2            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495047
# 3            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495043
# 4            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495044
# 5            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495045
# 6            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495046
# 7            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495049
# 8            \\text{Students are able to identify relationship between l (or ml) and cm³\n}    26          495050
# 9  \\text{Students are able to write down the notation and representations of fractions \n}    39          473272
# 10 \\text{Students are able to write down the notation and representations of fractions \n}    39          473270
# 11 \\text{Students are able to write down the notation and representations of fractions \n}    39          473269
# 12 \\text{Students are able to write down the notation and representations of fractions \n}    39          473262
# 13 \\text{Students are able to write down the notation and representations of fractions \n}    39          473261
# 14 \\text{Students are able to write down the notation and representations of fractions \n}    39          465453
# 15 \\text{Students are able to write down the notation and representations of fractions \n}    39          465452
...