R:使用%>%到group_by(id)进行关联

时间:2017-03-15 16:17:54

标签: r dplyr

我想在我的实验中计算每个参与者(称为A和B)的两个HeartRate和roomCO2Interp之间的互相关:

set.seed(395)
library(dplyr)

df2 <- data.frame(HeartRate= c(cumsum(rnorm(32*60*36,0,0.01)),
                               cumsum(rnorm(32*60*36,0,0.01))),
                  roomCO2Interp= c(cumsum(rnorm(32*60*36,0,0.01)),
                               cumsum(rnorm(32*60*36,0,0.01))),
                  ID = rep(c("A","B"), each=32*60*36))

enter image description here

我试图将pipe参数用于group_by(id),但它似乎无法正常工作:

crossCor<-df2 %>% group_by(id)%>%
  summarise(ccf(diff(roomCO2Interp), diff(HeartRate), type="correlation"))

Error in summarise_impl(.data, dots) : expecting a single value

0 个答案:

没有答案