CompoundDb icon indicating copy to clipboard operation
CompoundDb copied to clipboard

Create collapse_table, expand_table functions

Open jorainer opened this issue 7 years ago • 3 comments

Create functions that allow to collapse or expand a data.frame keeping unique values in some columns and list of elements in the other.

jorainer avatar Dec 04 '18 15:12 jorainer

Collapsing a data.frame turns out to be quite simple, but expanding it is tricky.

jorainer avatar Dec 06 '18 13:12 jorainer

I think I am looking for something similar in the database. It is basically a generalize way to do the synonyms nested column right?

My use case is that I have a list of compounds but only their name and CAS. I will retrieve the structure from databases but I get multiple hits for each CAS. So I want to save the possible structures and curate them from there.

I think you could use

df %>% tidyr::chop(-A) 

instead of .collapse_table. Unnesting can be done with tidyr::unchop(-A).

Alternative there is also df %>% tidyr::nest(data = -A) that keeps A unique and nests all the rest on one data.frame.

stanstrup avatar Feb 20 '20 13:02 stanstrup

Thanks. I will look into this.

jorainer avatar Feb 21 '20 08:02 jorainer