Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert dataframe to sankeytree list #23

Open
RomainBlancMathieu opened this issue Sep 16, 2021 · 0 comments
Open

Convert dataframe to sankeytree list #23

RomainBlancMathieu opened this issue Sep 16, 2021 · 0 comments

Comments

@RomainBlancMathieu
Copy link

RomainBlancMathieu commented Sep 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant