将多列合并为整洁数据我的数据集如下所示:unique.id abx.1 start.1 stop.1 abx.2 start.2 stop.2 abx.3 start.3 stop.3 abx.4 start.41 1 Moxi 2014-01-01 2014-01-07 PenG 2014-01-01 2014-01-07 Vanco 2014-01-01 2014-01-07 Moxi 2014-01-012 2 Moxi 2014-01-01 2014-01-02 Cipro 2014-01-01 2014-01-02 PenG 2014-01-01 2014-01-02 Vanco 2014-01-013 3 Cipro 2014-01-01 2014-01-05 Vanco 2014-01-01 2014-01-05 Cipro 2014-01-01 2014-01-05 Vanco 2014-01-014 4 Vanco 2014-01-02 2014-01-03 Cipro 2014-01-02 2014-01-03 Cipro 2014-01-02 2014-01-03 PenG 2014-01-025 5 Vanco 2014-01-01 2014-01-02 PenG 2014-01-01 2014-01-02 PenG 2014-01-01 2014-01-02 Cipro 2014-01-01 stop.4 intervention1 2014-01-07 02 2014-01-02 03 2014-01-05 14 2014-01-03 15 2014-01-02 0用一些代码创建: abxoptions <- c("Cipro", "Moxi", "PenG", "Vanco") df3 <- data.frame( unique.id = 1:5, abx.1 = sample(abxoptions,5, replace=TRUE), start.1 = as.Date(c('2014-01-01', '2014-01-01', '2014-01-01', '2014-01-02', '2014-01-01')), stop.1 = as.Date(c('2014-01-07', '2014-01-02', '2014-01-05', '2014-01-03', '2014-01-02')), abx.2 = sample(abxoptions,5, replace=TRUE), start.2 = as.Date(c('2014-01-01', '2014-01-01', '2014-01-01', '2014-01-02', '2014-01-01')), stop.2 = as.Date(c('2014-01-07', '2014-01-02', '2014-01-05', '2014-01-03', '2014-01-02')), abx.3 = sample(abxoptions,5, replace=TRUE), start.3 = as.Date(c('2014-01-01', '2014-01-01', '2014-01-01', '2014-01-02', '2014-01-01')), stop.3 = as.Date(c('2014-01-07', '2014-01-02', '2014-01-05', '2014-01-03', '2014-01-02')), abx.4 = sample(abxoptions,5, replace=TRUE), start.4 = as.Date(c('2014-01-01', '2014-01-01', '2014-01-01', '2014-01-02', '2014-01-01')),)以下解决方案无法满足我的需求: 收集多组列并将 多列组合成一列我怀疑Hadley令人惊奇的tidyr pakcage是要走的路......只是想不出来。任何帮助将不胜感激。
3 回答
- 3 回答
- 0 关注
- 557 浏览
添加回答
举报
0/150
提交
取消