如何以下列方式組合數據框的列?R(dplyr,tidyr):組合/聚合相關列
data <- data.frame(user.A = c(2,4,6),
user.B = c(11,13,15),
other.A = c(102,104,106),
other.B = c(201,103,105),
id = c('001', '004', '006'))
data
user.A user.B other.A other.B id
1 2 11 102 201 001
2 4 13 104 103 004
3 6 15 106 105 006
# Desired output.
user other id
1 2 102 001
2 11 201 001
3 4 104 004
4 13 103 004
5 6 106 006
6 15 105 006
我相信這可以dyplr
或tidyr
來完成。 dplyr
中的bind_rows
函數做了類似的操作,但不會創建此期望的輸出。
對於'reshape()'所有的仇恨基地,它有時真的很聰明。 – thelatemail