【发布时间】:2017-03-21 13:59:59
【问题描述】:
如何按以下方式组合数据框的列?
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 函数执行类似的操作,但不会创建所需的输出。
【问题讨论】: