下面的问题可以看成是“两列reshape to wide”,有几种方法可以用经典的方式解决,从base::reshape
(恐怖)到reshape2
. 对于两组情况,简单的子组连接效果最好。
我可以重新制定管道框架内的连接dplyr
吗?下面的例子有点傻,但我需要加入更长的管道链,我不想破坏它。
library(dplyr)
d = data.frame(subject= rep(1:5,each=2),treatment=letters[1:2],bp = rnorm(10))
d %>%
# Assume piped manipulations here
# Make wide
# Assume additional piped manipulations here
# Make wide (old style)
with(d,left_join(d[treatment=="a",],
d[treatment=="b",],by="subject" ))