Ich habe einen Datenrahmen wie unten (Namen 1. Reihe Spalte, 2. Reihe Datenelemente) gezeigteine verschachtelte Liste erstellen Obect
Von
Col_Name Col_Child_1 Col_Grand_Child_1 Col_Great_Grand_Child_1 Col_Great_Grand_Child_Size1 Col_Great_Grand_Child_2 Col_Great_Grand_Child_Size2 Col_Great_Grand_Child_3 Col_Great_Grand_Child_Size3 Col_Great_Grand_Child_4 Col_Great_Grand_Child_Size4
Flare analytics cluster AgglomerativeCluster 3938 CommunityStructure 3812 HierarchicalCluster 6714 MergeEdge 743
Ich versuche, die Datenelemente in der zweiten Reihe zu konvertieren (Flare, Analytik ....) in eine verschachtelte Liste, wie unten
gezeigt> Flare
$name
[1] "flare"
$children
$children[[1]]
$children[[1]]$name
[1] "analytics"
$children[[1]]$children
$children[[1]]$children[[1]]
$children[[1]]$children[[1]]$name
[1] "cluster"
$children[[1]]$children[[1]]$children
$children[[1]]$children[[1]]$children[[1]]
$children[[1]]$children[[1]]$children[[1]]$name
[1] "AgglomerativeCluster"
$children[[1]]$children[[1]]$children[[1]]$size
[1] 3938
$children[[1]]$children[[1]]$children[[2]]
$children[[1]]$children[[1]]$children[[2]]$name
[1] "CommunityStructure"
$children[[1]]$children[[1]]$children[[2]]$size
[1] 3812
$children[[1]]$children[[1]]$children[[3]]
$children[[1]]$children[[1]]$children[[3]]$name
[1] "HierarchicalCluster"
$children[[1]]$children[[1]]$children[[3]]$size
[1] 6714
$children[[1]]$children[[1]]$children[[4]]
$children[[1]]$children[[1]]$children[[4]]$name
[1] "MergeEdge"
$children[[1]]$children[[1]]$children[[4]]$size
[1] 743
Meine Versuche bisher sehr elementar sind und spiegelt meinen Kampf :).
x = list(name= test1$Col_Name, children = c(test1$Col_Child_1)
Jede Hilfe bei der Lösung dieses Puzzles wird sehr geschätzt. Danke im Voraus.
Im Folgenden finden Sie die Ausgabe von dput(test1)
test1 = structure(list(Col_Name = structure(2L, .Names = "row1", .Label = c("Col_Name",
"Flare"), class = "factor"), Col_Child_1 = structure(1L, .Names = "row1", .Label = c("analytics",
"Col_Child_1"), class = "factor"), Col_Grand_Child_1 = structure(1L, .Names = "row1", .Label = c("cluster",
"Col_Grand_Child_1"), class = "factor"), Col_Great_Grand_Child_1 = structure(1L, .Names = "row1", .Label = c("AgglomerativeCluster",
"Col_Great_Grand_Child_1"), class = "factor"), Col_Great_Grand_Child_Size1 = structure(1L, .Names = "row1", .Label = c("3938",
"Col_Great_Grand_Child_Size1"), class = "factor"), Col_Great_Grand_Child_2 = structure(2L, .Names = "row1", .Label = c("Col_Great_Grand_Child_2",
"CommunityStructure"), class = "factor"), Col_Great_Grand_Child_Size2 = structure(1L, .Names = "row1", .Label = c("3812",
"Col_Great_Grand_Child_Size2"), class = "factor"), Col_Great_Grand_Child_3 = structure(2L, .Names = "row1", .Label = c("Col_Great_Grand_Child_3",
"HierarchicalCluster"), class = "factor"), Col_Great_Grand_Child_Size3 = structure(1L, .Names = "row1", .Label = c("6714",
"Col_Great_Grand_Child_Size3"), class = "factor"), Col_Great_Grand_Child_4 = structure(2L, .Names = "row1", .Label = c("Col_Great_Grand_Child_4",
"MergeEdge"), class = "factor"), Col_Great_Grand_Child_Size4 = structure(1L, .Names = "row1", .Label = c("743",
"Col_Great_Grand_Child_Size4"), class = "factor")), .Names = c("Col_Name",
"Col_Child_1", "Col_Grand_Child_1", "Col_Great_Grand_Child_1",
"Col_Great_Grand_Child_Size1", "Col_Great_Grand_Child_2", "Col_Great_Grand_Child_Size2",
"Col_Great_Grand_Child_3", "Col_Great_Grand_Child_Size3", "Col_Great_Grand_Child_4",
"Col_Great_Grand_Child_Size4"), row.names = 2L, class = "data.frame")
Was Sie bisher versucht ? – Rentrop
@ Floo0, meine Frage aktualisiert, 'x = list (name = test1 $ Col_Name, children = c (test1 $ Col_Child_1)' Ich wünschte fast, ich hätte nichts versucht. –
Kannst du die Ausgabe von 'dput (test1)' hinzufügen um den Datenrahmen zu machen – TomNash