我有一个data.frame
> blah
Col1 Val1 Col2 Val2
1 A 1 B 10
2 A 2 B 20
3 A 3 B 30
structure(list(Col1 = structure(c(1L, 1L, 1L), .Label = "A", class = "factor"),
Val1 = structure(1:3, .Label = c("1", "2", "3"), class = "factor"),
Col2 = structure(c(1L, 1L, 1L), .Label = "B", class = "factor"),
Val2 = structure(1:3, .Label = c("10", "20", "30"), class = "factor")), .Names = c("COl1",
"Val1", "Col2", "Val2"), row.names = c(NA, -3L), class = "data.frame")
其中col1和col2是重复的id列。
我希望按列名拆分数据框并重新组合它们,以便最终结果如下所示。
> blah
Col Val
1 A 1
2 A 2
3 A 3
4 B 10
5 B 20
6 B 30
我一直在尝试使用融化和重塑,但没有太多运气。