我想在我的实验中计算每个参与者(称为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))
我试图将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