Creating a nested list obect
<p>I have a dataframe as shown below ( 1st row column names, 2nd row data elements)</p>

<p>From</p>

<pre><code> 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
</code></pre>

<p>I am trying to convert the data elements in the second row ( Flare, analytics....) into a nested list as shown below </p>

<pre><code>&gt; 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
</code></pre>

<p>My attempts so far are very elementary and reflects my struggle :).</p>

<pre><code>x = list(name= test1$Col_Name, children = c(test1$Col_Child_1) 
</code></pre>

<p>Any help on solving this puzzle is much appreciated. Thanks in advance.</p>

<hr>

<p>Below is the output from <code>dput(test1)</code> </p>

<pre><code>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")
</code></pre>