Re: [R] correlate vector & report p-value

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Tue 06 Dec 2005 - 07:59:25 EST

Vivien W. Chen wrote:
> Dear all,
>
> I've been struggling with this through this weekend, I finally decided to ask
> help from you. Please let me know if there is effective way to deal with this
> problem. Thanks!
>
> Here is the problem:
>
> I have two matrices.
>
> Matrix A:
>
> a b c
> 4 5 2
> 3 2 1
> 4 5 6
>
> Matrix B:
> d e f g h
> 3 4 5 2 1
> 2 3 7 8 6
> 8 5 1 3 4
>
> I would like to correlate vector a of matrix A with with vectors d,e,f,g,h of
> matrix "B" and save the p-value in a seperate result vector. Then, I would like
> to repeat this process using vector b of matrix A. Then, I would like to do
> this for vector c of matrix A.

To get all correlation coefficients:

   cor(A, B)

Which p-value do you mean, those from cor.test? You can get all by:
apply(A, 2, function(x)

     apply(B, 2, function(y) cor.test(x,y)$p.value))

Uwe Ligges

> Vivien W. Chen
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Dec 06 08:03:27 2005

This archive was generated by hypermail 2.1.8 : Tue 06 Dec 2005 - 09:34:04 EST