I'm currently working on a test where I have different regions with some associated statistic, and a comma-separated list of genes that lie in those regions. This list will be variable in number, and may not contain anything ("NA"
).
How can I "melt" this dataframe:
region_id statistic genelist
1 2.5 A, B, C
2 0.5 B, C, D, E
3 3.2 <NA>
4 0.1 E, F
Into something like this:
region_id statistic gene
1 2.5 A
1 2.5 B
1 2.5 C
2 0.5 B
2 0.5 C
2 0.5 D
2 0.5 E
3 3.2 <NA>
4 0.1 E
4 0.1 F