Hi,
May be this helps:
set.seed(25)
mt1<- matrix(sample(c(NA,1:40),20*200,replace=TRUE),ncol=200)
set.seed(487)
mt2<- matrix(sample(c(NA,1:80),20*200,replace=TRUE),ncol=200)
res<- sapply(seq_len(ncol(mt1)),function(i)
cor(mt1[,i],mt2[,i],use="complete.obs",method="pearson"))
A.K.
Hello, I've got the following problem.
I have to matrices each containing 200 time series.
Now I want to calculate the correlation of the first time series of each of the
matrices.
I use the following command:
cor(mts1[,1],mts2[,1], use="complete.obs", method=c("pearson"))
cor(mts1[,2],mts2[,2], use="complete.obs", method=c("pearson"))
cor(mts1[,3],mts2[,3], use="complete.obs", method=c("pearson"))
and so on..
I would like to repeat this for each of the 200 time series. As it
is quite painful to change the command 200 times I wanted to ask if
there's a loop function that can cover these series in a fast way?
Thanks in advance for your help
Best
Tom
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.