Cor work for me. Try this
Code:A=rnorm(90) Z= matrix(rnorm(90*100),nrow=90) cor(A,Z)
Hi. Very basic question, but I am looking to find the correlation coefficient (r, not r-squared, I need to know the sign) between a time-series A and all of the time-series embedded within the matrix Z (which might for example be a 90 x 100 matrix of temperature measurements, with 90 measured values at 100 different locations). A would then be of length 90 as well.
The desired output would be a list of 100 correlation values. I've tried using "lm" and cor functions (e.g., cor(A,Z)), but it didn't work whenever Z had more than one time series.
Cor work for me. Try this
Code:A=rnorm(90) Z= matrix(rnorm(90*100),nrow=90) cor(A,Z)
it works fine now...thanks
If u also need p-value
Code:install.packages("Hmisc") require(Hmisc) sapply(1:ncol(matrix2),function(i) rcorr(vector,matrix2[,i])$r[1,2] ) #r sapply(1:ncol(matrix2),function(i) rcorr(vector,matrix2[,i])$P[1,2] ) #Pvalue
|
|