[R] Please help on correlation matrix
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Sat Mar 25 13:55:01 CET 2006
On 25-Mar-06 stat stat wrote:
> hi everyone,
>
> Suppose I have three variables a, b, and c each with 10 values. Now I
> construct a corr matrix for them. Now I want to give the names of
> columns of corr matrix as a, b, c, i.e. the first column of corr matrix
> will have name as a second column with b and so on. Can anyone give
> me any code by which I can automatically assign the names of columns of
> corr matrix which are originally the names of variables?
>
> For example suppose next we have 5 variables r1...r5. I want to see
> the names of columns of corr matrix as r1...r5.
One of the following, or similar, does what you want. No?
> X<-cbind(rnorm(10),rnorm(10),rnorm(10))
> colnames(X)<-c("a","b","c")
> cor(X)
a b c
a 1.0000000 0.29895042 0.19601719
b 0.2989504 1.00000000 -0.04794445
c 0.1960172 -0.04794445 1.00000000
> a<-rnorm(10);b<-rnorm(10);c<-rnorm(10);X<-cbind(a,b,c)
> cor(X)
a b c
a 1.0000000 0.2825758 -0.7605892
b 0.2825758 1.0000000 -0.2322451
c -0.7605892 -0.2322451 1.0000000
Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 25-Mar-06 Time: 12:54:58
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list