I have the following data structure
ID Type Values
1 A 5; 7; 8
2 A 6
3 B 2; 3
and I would like to reshape it to the following using R:
ID Type Values
1 A 5
1 A 7
1 A 8
2 A 6
3 B 2
3 B 3
I've been trying to work out how to do it with plyr but without any success. What is the best way to do this?
Since you asked for a
plyr
solution, here you go:A
data.table
approach for coding eleganceThe answers so far are great. Here's yet another.
This solution uses the
colsplit()
function from the "reshape2" package. One downside is that it expects you to know the number of resulting columns needed.From here you can sort and drop columns as required to get your final desired output.
My shot:
Not a beautiful answer but it could be useful
This should work but maybe there's a better approach: