You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
The Sankeytrees from this package look great and I d like to make some with my data.
For this I d like to have an R function to convert a dataframe that has a "tree like structure" into a list that one can pass to the SankeyTree function.
Here is my toy data frame:
A1;B1;1
A1;B2;9
A2;B1;5
A2;B2;5
A3;NA;10
The last column in the dataframe is the count at each tips, that should be used to fed the 'n' variable at each node in the list...
Ideally the solution should not be hard coded so as to accept additional ranks (i.e additional columns).
The output should be:
tree.list <- list(name = "Overall", n = 30L, id = 1, terminalDescription = "", children = list(list(name = "A1", n = 10L, id = 2, terminalDescription = "", children=list(list(name="B1", n=1L, id=5, terminalDescription="B1"), list(name="B2", n=9L, id=6, terminalDescription="B2"))), list(name = "A2", n = 10L, id = 3, terminalDescription = "A2" , children=list(list(name="B1", n=5L, id=7, terminalDescription="B1"), list(name="B2", n=5L, id=8, terminalDescription="B2"))), list( name = "A3", n = 10L, id = 4, terminalDescription = "A3")))
Many many thanks in advance for your help!
Cheers,
Romain
The text was updated successfully, but these errors were encountered:
Hi,
The Sankeytrees from this package look great and I d like to make some with my data.
For this I d like to have an R function to convert a dataframe that has a "tree like structure" into a list that one can pass to the SankeyTree function.
Here is my toy data frame:
A1;B1;1
A1;B2;9
A2;B1;5
A2;B2;5
A3;NA;10
The last column in the dataframe is the count at each tips, that should be used to fed the 'n' variable at each node in the list...
Ideally the solution should not be hard coded so as to accept additional ranks (i.e additional columns).
The output should be:
tree.list <- list(name = "Overall", n = 30L, id = 1, terminalDescription = "", children = list(list(name = "A1", n = 10L, id = 2, terminalDescription = "", children=list(list(name="B1", n=1L, id=5, terminalDescription="B1"), list(name="B2", n=9L, id=6, terminalDescription="B2"))), list(name = "A2", n = 10L, id = 3, terminalDescription = "A2" , children=list(list(name="B1", n=5L, id=7, terminalDescription="B1"), list(name="B2", n=5L, id=8, terminalDescription="B2"))), list( name = "A3", n = 10L, id = 4, terminalDescription = "A3")))
Many many thanks in advance for your help!
Cheers,
Romain
The text was updated successfully, but these errors were encountered: