I have a dataset that contains one variable which is a list. I would now like to reshape the whole dataset with respect to the values in that list.
test_frame = data.frame(var1 = c("AAA", "BBB"))
test_frame$var2 = list(c("1", "2"), c("4", "5", "6"))
That data.frame looks like this:
var1 var2
1 AAA 1, 2
2 BBB 4, 5, 6
I would like to get something like this:
var1 var2
1 AAA 1
2 AAA 2
3 BBB 4
4 BBB 5
5 BBB 6
My idea was to create variables for the maximum number of entries in var2, then assign the different elements to those variables (leaving the rest as NA), then reshape and then filter out all NAs. That seems quite inefficient and not very elegant though. Any other/more efficient solutions?