Продвижение вложенных столбцов данных - PullRequest
0 голосов
/ 02 апреля 2019

У меня есть этот список из 2 кадров. Я хочу связать вместе фреймы данных, чтобы сформировать один фрейм данных.

dat <- list(structure(list(mbid = c("eda07157-11a6-4ab0-b9e1-faca2fde9bf3", 
"c8d8485f-cc09-402b-8ca1-4aeed9a88285", "76be87f4-ce0b-4715-baa8-f83c9627e5b2", 
"09c1a6a6-b77d-4f67-886d-bddd800aa4f8", "6a88e9e5-12a8-44ca-932a-1c0146d5f944", 
"218543bf-e7ce-4c30-9ee6-25cf6b3cd36a", "be0f5e41-7f98-484f-af05-2830e042bbee", 
"00a2c84a-782d-49c3-ac44-b00bf597b241", "833fc2d8-7ff6-45aa-af5f-3ad66f57fe8d", 
"76be87f4-ce0b-4715-baa8-f83c9627e5b2", "56c3c709-ccd7-45fc-9d7e-74b80fb2a21d", 
"76be87f4-ce0b-4715-baa8-f83c9627e5b2", "76be87f4-ce0b-4715-baa8-f83c9627e5b2", 
"76be87f4-ce0b-4715-baa8-f83c9627e5b2", "76be87f4-ce0b-4715-baa8-f83c9627e5b2", 
"c8d8485f-cc09-402b-8ca1-4aeed9a88285", "76be87f4-ce0b-4715-baa8-f83c9627e5b2", 
"d9d3490e-ed30-40a9-adfe-875f7d2ee5dc", "062f9a95-3b40-44f3-8438-65d476f35adb", 
"208621bb-9950-4207-a9c5-d299d4a54134"), name = c("Better At My Worst", 
"Top Rolled Down", "Lifelines & Superheroes", "Same Kind", "Heart Breaks", 
"Going Under (Didn't Have To)", "Blood Is Thicker Than Water", 
"Forever Begins Tonight", "Who Said It", "Lifelines & Superheroes", 
"Lay Some Love", "Lifelines & Superheroes", "Lifelines & Superheroes", 
"Lifelines & Superheroes", "Lifelines & Superheroes", "Top Rolled Down", 
"Lifelines & Superheroes", "Endless", "Nothing Good Comes Easy", 
"House"), date = structure(list(uts = c("1550752371", "1550752184", 
"1550751935", "1550751823", "1550751613", "1550751401", "1550751196", 
"1550750921", "1550750697", "1550750478", "1550750320", "1550750071", 
"1550749825", "1550749440", "1550749119", "1550748939", "1550748721", 
"1550748477", "1550748220", "1550748020"), `#text` = c("21 Feb 2019, 12:32", 
"21 Feb 2019, 12:29", "21 Feb 2019, 12:25", "21 Feb 2019, 12:23", 
"21 Feb 2019, 12:20", "21 Feb 2019, 12:16", "21 Feb 2019, 12:13", 
"21 Feb 2019, 12:08", "21 Feb 2019, 12:04", "21 Feb 2019, 12:01", 
"21 Feb 2019, 11:58", "21 Feb 2019, 11:54", "21 Feb 2019, 11:50", 
"21 Feb 2019, 11:44", "21 Feb 2019, 11:38", "21 Feb 2019, 11:35", 
"21 Feb 2019, 11:32", "21 Feb 2019, 11:27", "21 Feb 2019, 11:23", 
"21 Feb 2019, 11:20")), row.names = c(NA, 20L), class = "data.frame"), 
    artist = structure(list(mbid = c("6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", "6a87448d-a1bc-4e8a-8c4d-b7366662cc71", 
    "6a87448d-a1bc-4e8a-8c4d-b7366662cc71"), `#text` = c("The McClymonts", 
    "The McClymonts", "The McClymonts", "The McClymonts", "The McClymonts", 
    "The McClymonts", "The McClymonts", "The McClymonts", "The McClymonts", 
    "The McClymonts", "The McClymonts", "The McClymonts", "The McClymonts", 
    "The McClymonts", "The McClymonts", "The McClymonts", "The McClymonts", 
    "The McClymonts", "The McClymonts", "The McClymonts")), row.names = c(NA, 
    20L), class = "data.frame"), album = structure(list(mbid = c("7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "7bd6329b-b702-45f9-8420-be486dc1bd6d", "7bd6329b-b702-45f9-8420-be486dc1bd6d", 
    "14e7511a-4a43-4225-8403-312d9b19c2dc", "14e7511a-4a43-4225-8403-312d9b19c2dc", 
    "14e7511a-4a43-4225-8403-312d9b19c2dc"), `#text` = c("Here's To You & I", 
    "Here's To You & I", "Here's To You & I", "Here's To You & I", 
    "Here's To You & I", "Here's To You & I", "Here's To You & I", 
    "Here's To You & I", "Here's To You & I", "Here's To You & I", 
    "Here's To You & I", "Here's To You & I", "Here's To You & I", 
    "Here's To You & I", "Here's To You & I", "Here's To You & I", 
    "Here's To You & I", "Endless", "Endless", "Endless")), row.names = c(NA, 
    20L), class = "data.frame")), row.names = c(NA, 20L), class = "data.frame"), 
    structure(list(mbid = c("87dc9c1c-9cf0-38ad-a5e7-1e8005114e27", 
    "", "655b38ca-e847-3134-8da0-b4603349456c", "", "1782eb15-be64-4a7f-878b-e3c29fb0bd1c", 
    "1bc6476a-5545-3af6-aabf-dc812b498587", "10362cc6-40dd-30d3-a2da-7f753a0f3de4", 
    "620d1ddd-486a-3928-acb2-ec1625b4a929", "079a121e-3950-45d9-9a68-f10301241708", 
    "48a7c35a-6558-4e58-a72b-3044cea36564", "69d485ce-d6e7-3976-be8b-751b5a5067b7", 
    "1541af02-b377-42a7-813a-6a5a5576d61a", "156502d5-58c7-3c68-93be-c08eeab64974", 
    "538f206f-d5e4-3d23-8671-85b61d46b96e", "538f206f-d5e4-3d23-8671-85b61d46b96e", 
    "156502d5-58c7-3c68-93be-c08eeab64974", "1782eb15-be64-4a7f-878b-e3c29fb0bd1c", 
    "156502d5-58c7-3c68-93be-c08eeab64974", "0089b844-3367-4dae-ad24-16ffc41919a8", 
    "0089b844-3367-4dae-ad24-16ffc41919a8"), name = c("Wish I Could", 
    "Her e æ (Hei, her er jeg)", "Det fine vi hadd' sammen", 
    "When the Stars Go Blue (feat. Bono) - Live in Dublin", "You Weren't There", 
    "You Will Cry No More", "Do You Remember", "Here We Are", 
    "What If", "Hope You're Happy", "All I Can Say", "How Would It Be", 
    "Another Day", "Disguise", "Disguise", "Another Day", "You Weren't There", 
    "Another Day", "No Surrender", "No Surrender"), date = structure(list(
        uts = c("1548015363", "1548015090", "1548014829", "1548014569", 
        "1548014357", "1548014131", "1548013925", "1548013721", 
        "1548013487", "1548013182", "1548012905", "1548012667", 
        "1548000979", "1548000979", "1547992991", "1547992735", 
        "1547984975", "1547984727", "1547984379", "1547984126"
        ), `#text` = c("20 Jan 2019, 20:16", "20 Jan 2019, 20:11", 
        "20 Jan 2019, 20:07", "20 Jan 2019, 20:02", "20 Jan 2019, 19:59", 
        "20 Jan 2019, 19:55", "20 Jan 2019, 19:52", "20 Jan 2019, 19:48", 
        "20 Jan 2019, 19:44", "20 Jan 2019, 19:39", "20 Jan 2019, 19:35", 
        "20 Jan 2019, 19:31", "20 Jan 2019, 16:16", "20 Jan 2019, 16:16", 
        "20 Jan 2019, 14:03", "20 Jan 2019, 13:58", "20 Jan 2019, 11:49", 
        "20 Jan 2019, 11:45", "20 Jan 2019, 11:39", "20 Jan 2019, 11:35"
        )), row.names = c(NA, 20L), class = "data.frame"), artist = structure(list(
        mbid = c("2a141b9a-d109-4f4d-8085-781e7b194bca", "", 
        "e4098450-8838-4f9e-8a91-b1ccbf99b427", "", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "2a141b9a-d109-4f4d-8085-781e7b194bca", 
        "2a141b9a-d109-4f4d-8085-781e7b194bca", "70248960-cb53-4ea4-943a-edb18f7d336f", 
        "70248960-cb53-4ea4-943a-edb18f7d336f"), `#text` = c("Lene Marlin", 
        "Hver Gang Vi Møtes", "D.D.E.", "The Corrs", "Lene Marlin", 
        "Lene Marlin", "Lene Marlin", "Lene Marlin", "Lene Marlin", 
        "Lene Marlin", "Lene Marlin", "Lene Marlin", "Lene Marlin", 
        "Lene Marlin", "Lene Marlin", "Lene Marlin", "Lene Marlin", 
        "Lene Marlin", "Bruce Springsteen", "Bruce Springsteen"
        )), row.names = c(NA, 20L), class = "data.frame"), album = structure(list(
        mbid = c("3e0c3d27-ff51-41d4-bb42-e96a2eb1d950", "", 
        "1a131a36-1fd4-4a3a-b673-0f6e79d02c31", "f9964148-b49a-4567-83e2-8e27d3a069f7", 
        "6c293557-1a20-4cf6-80e8-5bb7d7ab4e55", "", "", "", "", 
        "", "", "", "", "", "", "", "", "", "020fb1b8-246f-3767-9736-db6bb552e729", 
        "020fb1b8-246f-3767-9736-db6bb552e729"), `#text` = c("Lost in a Moment", 
        "Hver gang vi møtes (Sesong 7)", "Jippi", "VH1 Presents The Corrs Live in Dublin", 
        "Another Day", "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Here We Are - Historier så langt", 
        "Here We Are - Historier så langt", "Born in the U.S.A.", 
        "Born in the U.S.A.")), row.names = c(NA, 20L), class = "data.frame")), row.names = c(NA, 
    20L), class = "data.frame"))

Использование

dat <- lapply(dat, rbind)

Фактически не меняет структуру в любом случае. Я думаю, это потому, что 3 столбца в каждом кадре данных фактически list s / dataframe сами по себе. Как я могу преобразовать эти столбцы данных в обычные символьные столбцы, чтобы их можно было связать вместе?

1 Ответ

2 голосов
/ 02 апреля 2019

Рассмотрим cbind для всех этих элементов, поскольку они имеют одинаковое количество списка верхнего уровня наблюдений:

new_dat_list <- lapply(dat_list, function(x) do.call(cbind, x))

new_dat_list
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...