How to use melt and dcast on hard data frames

I have a data frame that has one value in each cell, but my last column is a list. Example. There are 3 columns here. Columns X and Y have one value in each row. But column Z is actually a list. It can have several values ​​in each cell.

XYZ 1 adh, i, j 2 bej, k 3 cfl, m, n, o 

I need to create this:

  XYZ 1 adh 2 adi 3 adj 4 bej 4 bek 5 cfl 6 cfm 7 cfn 8 cfo 

Can someone help me figure this out? I am not sure how to use melt or dcast or any other function for this.

Thanks.

+1
source share
1 answer

unnest of tidyr works

 library(tidyr) unnest(dat, Z) 
+4
source

All Articles