我有这样一个数据框:
a1 a2 a3 a4 b c d1 d2 d3 d4
[1] 0 0 1 0 0 0 0 1 0 0
[2] 0 1 0 0 1 0 0 1 0 0
...
我想将其转换如下,我认为 reshape 在这里没有用,最好的方法是什么?
a b c d
[1] 0 0 0 0 # a and d as a1 and d1 of first row
[2] 0 0 0 1 # a and d as a2 and d2 of first row
[3] 1 0 0 0 # a and d as a3 and d3 of first row
[4] 0 0 0 0 # a and d as a4 and d4 of first row
[5] 0 1 0 0 # a and d as a1 and d1 of second row
[6] 1 1 0 1 # a and d as a2 and d2 of second row
[7] 0 1 0 0 # a and d as a3 and d3 of second row
[8] 0 1 0 0 # a and d as a4 and d4 of second row
...
谢谢你。