我有这样一个数据帧:如何选择性地将列转换为data.frame中的行?
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
...
我想它下面转换,我想重塑可能没有用处在这里,你会是最好的方法?
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
...
谢谢。
感谢完美分割,甚至尽管数据并不那么简单,但它的工作。 – 2013-03-27 16:40:47