# Thread: Basic question- Compute correlation with many time-series

1. ## Basic question- Compute correlation with many time-series

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.

2. ## Re: Basic question- Compute correlation with many time-series

Cor work for me. Try this
Code:
``````A=rnorm(90)
Z= matrix(rnorm(90*100),nrow=90)
cor(A,Z)``````

3. ## Re: Basic question- Compute correlation with many time-series

it works fine now...thanks

4. ## Re: Basic question- Compute correlation with many time-series

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``````

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts