Transform a dataframe into a tree structure list of lists
问题 I have a data.frame with two columns representing a hierarchical tree, with parents and nodes. I want to transform its structure in a way that I can use as an input for the function d3tree , from d3Network package. Here's my data frame: df <- data.frame(c("Canada","Canada","Quebec","Quebec","Ontario","Ontario"),c("Quebec","Ontario","Montreal","Quebec City","Toronto","Ottawa")) names(df) <- c("parent","child") And I want to transform it to this structure Canada_tree <- list(name = "Canada",