I'm running a cross correlation analysis and I'm trying to loop the analysis through pairs of columns in a dataframe. I've created a list to populate the resultant output but it doesn't populate correctly. The print function works though.
I've done some research but still have not found the solutions to this problem. Please help.
library(tseries)
blahthresholdtest <- matrix(rnorm(100, 50, 1), nrow = 20, ncol = 4)
thislist <- list()
test <- for(i in seq(1, ncol(blahthresholdtest), 2)){
for(k in seq(1, ncol(blahthresholdtest), 1)) {
vector <- numeric(ncol(blahthresholdtest))
ccftime <- ccf(blahthresholdtest[, i], blahthresholdtest[, i+1],
type="correlation", na.action=na.omit, plot=FALSE)
crosscorr <- cbind(ccftime$acf, ccftime$lag)
crosscorr <- as.data.frame(crosscorr)
colnames(crosscorr) <- c("CCF", "lag")
vector[k+1] <- with(crosscorr, lag[CCF == max(CCF)])
thislist[[k]] <- vector
}
print(vector[k])
print(vector[k + 1])
}
thislist
do.call(rbind, thislist)