我有一个这样的数据集:
ID child1 child2 child3
1 ADE SOLA BIMPE
2 TUNDE BYRA FUNMY
我想要这个输出
1D child
1 ADE
1 SOLA
1 BIMPE
2 TUNDE
2 BYRA
2 FUNMY
请我如何在R中编写代码以获取该输出
答案 0 :(得分:0)
使用reshape2
来查看melt
软件包
答案 1 :(得分:0)
data <- data.frame(
ID = 1:2,
child1 = c("ADE", "TUNDE"),
child2 = c("SOLA", "BYRA"),
child3 = c("BIMPE", "FUNMY"),
stringsAsFactors = FALSE
)
melt(data, id.vars = "ID", value.name = "child")
ID variable child
1 1 child1 ADE
2 2 child1 TUNDE
3 1 child2 SOLA
4 2 child2 BYRA
5 1 child3 BIMPE
6 2 child3 FUNMY